JSFiddle - React, Tailwind, and code Playground
HTML
<canvas id="canvas" width="400" height="400"></canvas>
JavaScript
window.requestAnimFrame = (function (callback) {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) {
window.setTimeout(callback, 1000 / 60);
};
})();
var app = {
tick: 0,
fps: 60,
angle: 0,
rings: new Array
};
app.canvas = $('#canvas')[0];
app.ctx = canvas.getContext("2d");
app.centerx = app.canvas.width / 2;
app.centery = app.canvas.height / 2;
app.config = {
radius: 180,
elements: 25,
lineWidth: 6
};
app.all_finished = false;
// Color generating code stolen/borrowed/copied from http://krazydad.com/tutorials/makecolors.php
app.byte2Hex = function (n) {
var nybHexString = "0123456789ABCDEF";
return String(nybHexString.substr((n >> 4) & 0x0F, 1)) + nybHexString.substr(n & 0x0F, 1);
}
app.RGB2Color = function (r, g, b) {
return '#' + app.byte2Hex(r) + app.byte2Hex(g) + app.byte2Hex(b);
}
app.generateColor = function (elem, limit) {
var frequency = 2 * Math.PI / limit;
red = Math.sin(frequency * elem + 0) * 127 + 128;
green = Math.sin(frequency * elem + Math.PI / 2) * 127 + 128;
blue = Math.sin(frequency * elem + Math.PI) * 127 + 128;
return app.RGB2Color(red, green, blue);
}
// Colors end
app.drawRing = function (ctx, x, y, rad, c, color, angle) {
ctx.beginPath();
ctx.arc(x, y, rad, angle, c);
ctx.lineWidth = app.config.lineWidth;
ctx.strokeStyle = color;
ctx.stroke();
}
app.redraw = function () {
app.ctx.clearRect(0, 0, app.canvas.width, app.canvas.height);
for (j = 0; j < app.rings.length; j++) {
var ring = app.rings[j];
if( ring.direction == 0 ){
ring.c += ring.step;
var c = app.angle + ring.c;
var angle = app.angle;
if( ring.c >= 2*Math.PI ){
ring.c = 2*Math.PI;
...