-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsquares.js
49 lines (37 loc) · 1.02 KB
/
squares.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const SQUARE_SIZE = 312;
const DRAW_RATE = 3;
const squaresToFill = [];
function setup() {
createCanvas(1536, 864);
background(30);
const w = round(width / SQUARE_SIZE);
const h = round(height / SQUARE_SIZE);
for (const x of Array(w).keys()) {
for (const y of Array(h).keys()) {
squaresToFill.push([x, y]);
}
}
}
class Square {
constructor(x, y) {
this.x = x;
this.y = y;
this.color = color(random(70, 255), random(70, 255), random(70, 255), 200);
}
draw() {
push();
fill(this.color);
square(this.x*SQUARE_SIZE, this.y*SQUARE_SIZE, SQUARE_SIZE);
pop();
}
}
function draw() {
if (frameCount % DRAW_RATE == 0 && squaresToFill.length > 0) {
const index = round(random(0, squaresToFill.length-1));
const x = squaresToFill[index][0];
const y = squaresToFill[index][1];
const square = new Square(x, y);
square.draw();
squaresToFill.splice(index, 1);
}
}