JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://code.jquery.com/jquery-2.2.2.min.js"></script>
<body>
<canvas id="canvas"></canvas>
</body>
JavaScript
// Canvas ----------------------------------
var _width = 900;
var _height = 900;
// Circle ----------------------------------
var _cox = 350;
var _coy = 350;
var _cor = 200;
var _cs = 80;
var _cr = null;
// -----------------------------------------
var _canvas;
var _ctx;
// -----------------------------------------
var _drawInterval;
var _circle = Array();
// -----------------------------------------
function init() {
_canvas = document.getElementById("canvas");
_ctx = _canvas.getContext("2d");
_canvas.width = _width;
_canvas.height = _height;
// -----------------------------------------
$(document).on('mousemove', function(e){
_cx = e.clientX;
_cy = e.clientY;
});
// -----------------------------------------
_drawInterval = setInterval(update, 33);
}
function createCircle() {
var a = 0;
var e = 0;
_circle = Array();
for (var i = 0; i < _cs; i++) {
x = _cox + _cr * Math.cos( a * Math.PI / 180 ) + Math.random()*20;
y = _coy + _cr * Math.sin( a * Math.PI / 180 ) + Math.random()*20;
_circle.push( { x:x, y:y })
a += 360/_cs;
}
}
function update(){
if( _cr == null) {
_cr = _cor;
}
_cox = _cx;
_coy = _cy;
createCircle();
draw();
}
function draw() {
_ctx.clearRect(0,0,_width,_height);
_ctx.beginPath();
for (var i = 0; i < _circle.length; i++) {
var pos = _circle[i];
_ctx.lineWidth = 0;
_ctx.arc(pos.x, pos.y, 2, 0, 5 * Math.PI, false);
_ctx.fillStyle = '#13a8a4';
_ctx.fill();
_ctx.closePath();
}
_ctx.beginPath();
_ctx.lineJoin = "round";
_ctx.lineWidth = 1;
for (var i = 0; i < _circle.length; i++) {
var pos = _circle[i];
if( i == 0 ) {
_ctx.moveTo(pos.x, pos.y);
}
_ctx.lineTo(pos.x, pos.y);
}
_ctx.closePath();
_ctx.stroke();
_ctx.fill();
// -----------------------------------------
}
$(document).ready( function(){
init();
});