JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://jeroen.ishetaldonderdag.nl/js/libs/simpleParticle.js"></script>
<canvas id="canvas">
<p>This is a <a href="http://dev.w3.org/html5/spec/Overview.html#the-canvas-element">canvas</a> demo and your browser doesn't seem to support it :(</p>
</canvas>
CSS
html, body { height: 100%; margin: 0; overflow: hidden; width: 100%; }
canvas { background-color: #000; height: 100%; widht: 100%; }
JavaScript
// Global variables
var SCREEN_WIDTH = window.innerWidth,
SCREEN_HEIGHT = window.innerHeight,
HALF_WIDTH = window.innerWidth / 2,
HALF_HEIGHT = window.innerHeight / 2,
MAX_PARTICLES = 1500,
mouseX = HALF_WIDTH,
mouseY = HALF_HEIGHT,
particles = [],
particle;
// This is where it all starts
(function(d, canvas)
{
canvas = d.getElementById(canvas);
if (!canvas.getContext) return; // Check for support
context = canvas.getContext('2d');
canvas.height = SCREEN_HEIGHT;
canvas.width = SCREEN_WIDTH;
animate();
}
)(document, 'canvas');
// Create the particles
// Playing around with the values below is highly encouraged
function makeParticle(particleCount)
{
for (var i = 0; i < particleCount; i++)
{
// Using a modified version of simpleParticle.js
// http://jeroen.ishetaldonderdag.nl/js/libs/simpleParticle.js
var particle = new Particle((mouseX - 50), (mouseY - 50));
particle.velX = Math.random() * 10 - 5;
particle.velY = Math.random() * 10 - 5;
particle.rgbColor = rndRGBColor();
particle.drag = 0.9;
particle.gravity = 0.5;
particle.size = 10;
particle.shrink = 0.95;
particle.fade = 0.03;
particles.push(particle);
}
}
// Animate using requestAnimFrame
function animate()
{
requestAnimFrame(animate);
loop();
}
// Loop throught the particles and update their values
function loop()
{
makeParticle(2);
document.addEventListener('mousemove', onMouseMove, false);
context.clearRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
for (var i = 0, partLen = particles.length; i < partLen; i++)
{
var particle = particles[i];
particle.render(context);
particle.update();
}
while (particles.length > MAX_PARTICLES)
{
particles.shift();
}
}
// Keep track of the...