Skip to content

Instantly share code, notes, and snippets.

@64lines
Last active September 22, 2019 16:57
Show Gist options
  • Save 64lines/436d0cccc6b3054ed7ef2c4fb3ac7292 to your computer and use it in GitHub Desktop.
Save 64lines/436d0cccc6b3054ed7ef2c4fb3ac7292 to your computer and use it in GitHub Desktop.
[ALGORITHMIC ART] - Heartbeat
<body>
<canvas id="can" style="height:100%; width: 100%;"
style="border:1px solid #c3c3c3;">
</canvas>
<script>
var canvas = document.getElementById("can");
var ctx = canvas.getContext("2d");
num = 0;
colornum = 0;
function ran(par) {
return Math.floor(Math.random() * par);
}
function paint() {
size = 2
sh = screen.width;
color = "#" + colornum.toString(16);
for(var i = 0; i < sh*10; i++) {
ctx.fillStyle = color;
ctx.fillRect(ran(sh), ran(sh), size, size);
}
num++;
colornum += color != '#fff' ? 1 : 0;
requestAnimationFrame(paint);
}
requestAnimationFrame(paint);
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment