JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
<canvas id="bgcanvas"></canvas>
</body>
</html>
CSS
body
{
margin:0px;
padding:0px;
}
JavaScript
function ribbon( context )
{
this.init( context );
}
ribbon.prototype =
{
context: null,
mouseX: null,
mouseY: null,
painters: null,
interval: null,
init: function( context )
{
var scope = this;
this.context = context;
this.mouseX = SCREEN_WIDTH / 2;
this.mouseY = SCREEN_HEIGHT / 2;
this.painters = [];
this.unpainters = [];
this.timers = [];
for (var i = 0; i < STROKES; i++)
{
var ease = Math.random() * 0.2 + EASING;
console.log(ease);
this.painters.push({ dx: SCREEN_WIDTH / 2, dy: SCREEN_HEIGHT / 2, ax: 0, ay: 0, div: 0.1, ease: ease });
}
this.interval = setInterval(update, REFRESH_RATE );
function update()
{
var i;
this.context.lineWidth = BRUSH_SIZE;
this.context.strokeStyle = "rgba(" + COLOR[0] + ", " + COLOR[1] + ", " + COLOR[2] + ", " + BRUSH_PRESSURE + ")";
for (i = 0; i < scope.painters.length; i++)
{
scope.context.beginPath();
var dx = scope.painters[i].dx;
var dy = scope.painters[i].dy;
scope.context.moveTo(dx, dy);
var dx1 = scope.painters[i].ax = (scope.painters[i].ax + (scope.painters[i].dx - scope.mouseX) * scope.painters[i].div) * scope.painters[i].ease;
scope.painters[i].dx -= dx1;
var dx2 = scope.painters[i].dx;
var dy1 = scope.painters[i].ay = (scope.painters[i].ay + (scope.painters[i].dy - scope.mouseY) * scope.painters[i].div) * scope.painters[i].ease;
scope.painters[i].dy -= dy1;
var dy2 = scope.painters[i].dy;
scope.context.lineTo(dx2, dy2);
scope.context.stroke();
for(j=FADESTEPS;j>0;j--)
{
setTimeout(function()
{
...