-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
67 lines (60 loc) · 1.38 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
let x = [];
let y = [];
let amplitude = [];
let a;
let b;
let c;
let angle = 0;
let num;
let size = 20;
let period = 2;
let shift = 1;
function setup() {
createCanvas(windowWidth, windowHeight);
num = width / size;
angleMode(DEGREES);
amplitude = min(windowWidth / 4, windowHeight / 4);
strokeWeight(1);
}
function draw() {
// translate(0, windowHeight/2);
background(215, 215, 217);
// Draw background grid
for (let i = 0; i < windowWidth; i +=20) {
for (let j = 0; j < windowHeight; j +=20) {
stroke(0);
rect(i, j,0, windowHeight);
}
}
// Red section
for (let a = 0; a < num; a++) {
angle = (a / (num - 1)) * 180 * period;
x[a] = a * size;
y[a] = amplitude * 2 * sin(angle - shift);
fill(255, 0, 0);
stroke(0);
rect(x[a], y[a], 20, windowHeight);
}
// Section 2
for (let c = 0; c < num; c++) {
angle = ((c / (num - 25)) * 180) / period;
x[c] = c * size;
y[c] = amplitude * sin(angle - shift);
fill(110, 25, 25);
stroke(0);
rect(x[c], y[c], 20, windowHeight/2);
}
// Section 3
for (let b = 0; b < num; b++) {
angle = ((b / (num - 10)) * 180) / period;
x[b] = b * size;
y[b] = amplitude * cos(angle + shift);
fill(0, 166, 209,50);
stroke(0);
rect(x[b], y[b], 20, windowHeight/2);
}
shift += 1.2;
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}