JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<canvas id="canvas"></canvas>
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
function Particles(){
//particle colors
this.colors = [
'19, 19, 19'
]
//adds gradient to particles on true
this.blurry = false;
//adds white border
this.border = false;
//particle radius min/max
this.minRadius = 35;
this.maxRadius = 35;
//particle opacity min/max
this.minOpacity = 1;
this.maxOpacity = 1;
//particle speed min/max
this.minSpeed = .05;
this.maxSpeed = .5;
//frames per second
this.fps = 60;
//number of particles
this.numParticles = 30;
this.particles = [];
//required canvas variables
this.canvas = document.getElementById('canvas');
this.ctx = this.canvas.getContext('2d');
this.animationStopped = false;
}
/**
* Initializes everything
* @method init
*/
Particles.prototype.init = function(){
this.render();
this.createCircle();
}
Particles.prototype._rand = function(min, max){
return Math.random() * (max - min) + min;
}
Particles.prototype.render = function(){
var self = this,
wHeight = $(window).height(),
wWidth = $(window).width();
self.canvas.width = wWidth;
self.canvas.height = wHeight;
elemLeft = self.canvas.offsetLeft,
elemTop = self.canvas.offsetTop,
$(window).on('resize', self.render);
elements = this.particles;
elementSize = this.minRadius;
self.canvas.addEventListener('mousemove',function(event) {
mouseIsOverOneObject = false;
var x = event.pageX - elemLeft,
y = event.pageY - elemTop;
elements.forEach(function(element) {
if (mouseIsOverOneObject == false && self.testClickInCircle(x,y,element.xPos,element.yPos,elementSize))
mouseIsOverOneObject = true;
});
if (mouseIsOverOneObject == true) {
self.stop();
} else {
self.resume();
}
}, false);
}
Particles.prototype.testClickInCircle = function(x, y, cx, cy, radius) {
var distancesquared = (x -...