JSFiddle - React, Tailwind, and code Playground
HTML
<canvas id="canvas1" width="500" height="500"></canvas>
JavaScript
var can = document.getElementById('canvas1');
var ctx = can.getContext('2d');
var can2 = document.createElement('canvas');
can2.width = can.width;
can2.height = can.height;
var ctx2 = can2.getContext('2d');
function addJitteryBezier(fromx, fromy, tox, toy) {
var diffx = tox - fromx;
var diffy = toy - fromy;
var neg = Math.random()*diffy/5; // so the x value can go positive or negative from the typical
ctx2.bezierCurveTo(
-neg + fromx + 2*(Math.random()*diffy/8), fromy + .3*diffy,
-neg + fromx + 2*(Math.random()*diffy/8), fromy + .6*diffy,
tox, toy
);
}
ctx2.beginPath();
ctx2.moveTo(50,0);
var i = 0;
while (i < 500) {
addJitteryBezier(50, i, 50, i+50);
i+= 50;
}
ctx2.stroke();
// so now everything is drawn onto ctx2 and nothing is on our regular canvas
// We could draw all of can2 onto our first canvas with the line:
// ctx.drawImage(can2, 0, 0);
// Instead we will draw it onto the first canvas bit by bit
//drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh)
var amount = 1;
function drawMore() {
ctx.clearRect(0,0,can.width, can.height);
ctx.drawImage(can2, 0, 0, can.width, amount, 0, 0, can.width, amount);
amount++;
}
setInterval(drawMore, 90);