Circles

Developer
Size
3,817 Kb
Views
42,504

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 Previews

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); } });
Circles - Script Codes
Circles - Script Codes
Home Page Home
Developer David Storey
Username davidpanik
Uploaded July 12, 2022
Rating 3
Size 3,817 Kb
Views 42,504
Do you need developer help for Circles?

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!

David Storey (davidpanik) Script Codes
Create amazing captions with AI!

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!