Created
September 23, 2019 15:19
-
-
Save 64lines/0dada6f52df8181f3c891da780d3a420 to your computer and use it in GitHub Desktop.
[ALGORITHMIC ART] - Fabric Waves
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> | |
<canvas id="can" width="1200" height="600"> | |
</canvas> | |
<script> | |
ctx = can.getContext("2d"); | |
size = 2; | |
space = 1; | |
lines = 1000; | |
period = 1 / 30; | |
amplitude = 20; | |
colornum = 16711680 | |
ran = par => Math.floor(Math.random() * par); | |
function gencol(start, lim) { | |
listcol = [] | |
lim = (start + lim) | |
for(i = start; i < lim; i++) { | |
listcol.push("#" + ran(colornum).toString(16)); | |
} | |
return listcol; | |
} | |
function paint() { | |
listcol = gencol(colornum, lines); | |
for(num = 0; num < screen.width; num++) { | |
for(i = 0; i < lines; i++) { | |
ctx.fillStyle = listcol[i]; | |
y = (amplitude * Math.sin(period * num)) + (i * space) | |
ctx.fillRect(num, y - 200, size, size); | |
} | |
} | |
} | |
paint(); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment