-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
74 lines (56 loc) · 1.37 KB
/
sketch.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
let squares = [];
let newGrid = [];
let sz = 60;
let szIncrement = 1; // Ensure this is non-zero to see the animation
let growing = true;
let t = 0;
let lastUpdateTime;
let updateInterval = 10000;
let display;
let slider;
function setup() {
createCanvas(1600, 1090, P2D);
smooth(2); // Enable anti-aliasing for smoother images
frameRate(60);
slider = createSlider(0, 255);
slider.position(1900, 100);
slider.size(200);
// Initialize DisplayGrid
display = new DisplayGrid();
// Populate the initial squares grid
populateGrid();
lastUpdateTime = millis(); // Initialize the last update time
}
function draw() {
background(255, 0, 100);
let currentTime = millis();
if (currentTime - lastUpdateTime >= updateInterval) {
lastUpdateTime = currentTime;
if (growing) {
sz += szIncrement;
if (sz >= 100) { // Max size before shrinking
growing = false;
}
} else {
sz -= szIncrement;
if (sz <= 100) { // Min size before growing
growing = true;
}
}
populateGrid();
}
display.grid();
}
function populateGrid() {
squares = [];
newGrid = [];
for (let x = 0; x < width; x += sz) {
for (let y = 0; y < height; y += sz) {
squares.push(new GridSquare(x, y, sz, sz));
}
}
for (let i = 0; i < squares.length; i++) {
let sqr = squares[i];
sqr.subDiv(sqr);
}
}