Last active
May 6, 2020 05:45
-
-
Save killa-kyle/2a91bc006154a0799dd357e165afb569 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
let | |
cv = document.createElement('canvas') | |
rect_max_size_x = 50, | |
cv_size_x = 1000, | |
cv_size_y = 572; | |
cv.width = cv_size_x; | |
cv.height = cv_size_y; | |
let ctx = cv.getContext('2d'); | |
document.getElementsByTagName('body')[0].appendChild(cv); | |
let | |
rect_count = 2000, | |
rect_pos_x = [], | |
rect_pos_y = [], | |
rect_size_x = [], | |
rect_size_y = [], | |
rect_speed = []; | |
for (let i = 0; i < rect_count; i++) | |
{ | |
rect_pos_x[i] = Math.random() * cv_size_x; | |
rect_pos_y[i] = Math.random() * cv_size_y; | |
rect_size_x[i] = 5 + Math.random() * 45; | |
rect_size_y[i] = 5 + Math.random() * 45; | |
rect_speed[i] = 0.1 + Math.random() * 4.0; | |
} | |
function update() | |
{ | |
cv.width = cv_size_x; | |
ctx.fillStyle = "hsl(0,0%,100%)"; | |
ctx.strokeStyle = "hsl(0,0%,0%)"; | |
for (let i = 0; i < rect_count; i++) | |
{ | |
rect_pos_x[i] += rect_speed[i]; | |
if (rect_pos_x[i] >= cv_size_x) | |
{ | |
rect_pos_x[i] -= cv_size_x + rect_max_size_x; | |
} | |
ctx.fillRect (rect_pos_x[i], rect_pos_y[i], rect_size_x[i], rect_size_y[i]); | |
ctx.strokeRect (rect_pos_x[i], rect_pos_y[i], rect_size_x[i], rect_size_y[i]); | |
} | |
requestAnimationFrame(update); | |
} | |
requestAnimationFrame(update); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment