Circles
How do I make an circles?
What is a circles? How do you make a circles? This script and codes were developed by David Storey on 12 July 2022, Tuesday.
Circles - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Circles</title> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ body { color: #000; background-color:#1D1F20; margin: 0; padding: 0;
}
canvas { background-color:#000; display: block; margin: 0; width: 100%; height: 100%; position: absolute; top: 0; right: 0; left: 0; right: 0;
}
#score { position: fixed; top: 10px; left: 10px; color: white;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <canvas id="canvas"></canvas>
<div id="score">0</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Circles - Script Codes CSS Codes
body { color: #000; background-color:#1D1F20; margin: 0; padding: 0;
}
canvas { background-color:#000; display: block; margin: 0; width: 100%; height: 100%; position: absolute; top: 0; right: 0; left: 0; right: 0;
}
#score { position: fixed; top: 10px; left: 10px; color: white;
}
Circles - Script Codes JS Codes
$(function () { var myCanvas, context, width, height; var planets = [], noOfPlanets = 1; var colours = ['#FFE97F', '#A5FF7F', '#FF7F7F', '#FFB27F', '#7FC9FF', '#7F92FF']; var mouseDown = false, fingerSize = 2, mouseX = 0, mouseY = 0, score = 10000, gameOver = false; window.requestAnimFrame = (function(){ return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback, element){ window.setTimeout(callback, 1000 / 60); }; })(); function merge(alpha, beta) { for (var x in beta) { alpha[x] = beta[x]; } return alpha; } var Planet = function(settings) { var obj = { x: 0, y: 0, size: 0, colour: '#FFFFFF', opacity: 1, direction: 0, speed: 0, value: 0, move: function() { return this; }, draw: function() { if (this.size > 0) drawGlowingCircle(this.x, this.y, this.size, this.colour, this.opacity); return this; } }; return merge(obj, settings); }; if ($("canvas").length > 0) { myCanvas = $("#canvas")[0]; context = myCanvas.getContext("2d"); width = myCanvas.width; height = myCanvas.height; init(); } function createPlanet() { var planet = (Planet({ x: random(width * 0.25, width * 0.75), y: random(height * 0.25, height * 0.75), size: random(50, 90), colour: colours[random(0, colours.length-1)], speed: random(20, 50) / 100 })); return planet; } function init() { resizeCanvas(); // Name says it all, init. for (var x = 0; x < noOfPlanets; x++) { planets.push(createPlanet()); } setScore(score); } function update() { // This is called every frame. Perform your logic here if (gameOver) return false; setScore(score - 1); if (score < 1) { $('#score').html('GAME OVER You hit zero!'); gameOver = true; mouseDown = false; } if (mouseDown) { var onPlanet = false; for (var x = 0, length = planets.length; x < length; x++) { //planets[x].size -= planets[x].speed; // Circular collision detection var dx = mouseX - planets[x].x, dy = mouseY - planets[x].y, distance = Math.sqrt(dx * dx + dy * dy); if (distance < fingerSize + planets[x].size) onPlanet = true; setScore(score + planets[x].value); } if (onPlanet) { //setScore(score + 1); } else { $('#score').html('GAME OVER - Final score ' + score); gameOver = true; } } for (var x = 0, length = planets.length; x < length; x++) { planets[x].size -= planets[x].speed; planets[x].value += Math.round(planets[x].speed* 50); if (planets[x].size < 1) planets[x] = createPlanet(); } } function draw() { // Canvas is like drawing on glass (it is transparent, if you want to add in an html background). // You might want to wipe the glass clean every frame to stop smudges... But then again, you might not. if (gameOver) return false; context.clearRect(0, 0, width, height); //drawGlowingCircle(50, 50, 20, '#FF0000', 1); for (var x = 0, length = planets.length; x < length; x++) { planets[x].draw(); } // The .save() and .restore() functions improve performance // by limiting re-drawing of the canvas to screen. context.save(); // Draw stuff to the context. // Then update the display. context.restore(); } function animate() { // Called everyframe, and sequences logic then redraw. This should give you 60fps update(); draw(); requestAnimFrame(animate); } // Kick things off... delay = setTimeout(animate, 10); function drawPoint(x, y, size, colour) { context.fillStyle = colour; context.fillRect(x, y, size, size); } function drawLine(x1, y1, x2, y2, size, colour, opacity) { setOpacity(opacity); context.beginPath(); context.strokeStyle = colour; context.lineWidth = size; context.moveTo(x1, y1); context.lineTo(x2, y2); context.stroke(); context.closePath(); } function drawCircle(x, y, size, colour, opacity) { setOpacity(opacity); context.fillStyle = colour; context.beginPath(); context.arc(x, y, size, 0, 2 * Math.PI); context.fill(); } function drawGlowingCircle(x, y, size, colour, opacity) { drawCircle(x, y, size * 1.30, colour, opacity * 0.1); drawCircle(x, y, size * 1.25, colour, opacity * 0.1); drawCircle(x, y, size * 1.20, colour, opacity * 0.1); drawCircle(x, y, size * 1.15, colour, opacity * 0.1); drawCircle(x, y, size * 1.10, colour, opacity * 0.1); drawCircle(x, y, size * 1.05, colour, opacity * 0.1); drawCircle(x, y, size * 1.00, colour, opacity * 1.0); } function setOpacity(alpha) { context.globalAlpha = alpha; } function random(min, max) { return (Math.floor(Math.random() * ((max - min) + 1) + min)); } function resizeCanvas() { myCanvas.width = $("canvas").width(); myCanvas.height = $("canvas").height(); width = myCanvas.width; height = myCanvas.height; } $(window).on('resize', resizeCanvas); $('canvas') .on('mousedown', function(event) { mouseDown = true; mouseX = event.pageX; mouseY = event.pageY; }) .on('mouseup', function() { mouseDown = false; }); function setScore(n) { score = n; $('#score').html(score); } });
Developer | David Storey |
Username | davidpanik |
Uploaded | July 12, 2022 |
Rating | 3 |
Size | 3,817 Kb |
Views | 42,504 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
A Pen by David Storey | 1,682 Kb |
Cage-o-graph | 5,338 Kb |
Blobs | 3,143 Kb |
Find most common word | 1,605 Kb |
Rogue Engine | 3,505 Kb |
The Swear Machine | 2,532 Kb |
Local Weather | 3,177 Kb |
Spiral Art Maker | 4,185 Kb |
Twitter Extractor | 2,327 Kb |
Virtual vinyl | 3,474 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Pruebas de d3.js | Juanmanuelcarnerero | 2,485 Kb |
Funny menu | AxeLVaisper | 4,671 Kb |
Horizontal Navigation with Floats | Gymratpacks | 5,403 Kb |
Wave Lines | Mikehobizal | 4,023 Kb |
Draggables in pure angular | Rlo206 | 5,167 Kb |
12 DAYS OF XMAS | Proto78 | 2,313 Kb |
A bit of elegance | Hackthevoid | 9,095 Kb |
Material design - button rainbow circle | Kunukn | 3,652 Kb |
Tree growth tests | Orchard | 3,818 Kb |
Rainbow Drops | Csbarnes | 2,365 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!