-
Notifications
You must be signed in to change notification settings - Fork 2
/
day_16.pde
72 lines (53 loc) · 1.5 KB
/
day_16.pde
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
float offset = 0;
int nLines = 20;
float vSize = 100;
/**
* Display a wave with different frequencies, offset and location
*/
void drawWave(int steps, float cycles, float offset, float yPos, float hSize) {
noFill();
stroke(0, 50);
// Center on x
float startX = width / 2 - hSize / 2;
beginShape();
for (int i = 0; i <= steps; i++) {
float x = startX + i * (hSize / steps);
float angle = offset + map(x, 0, width, 0, TWO_PI * cycles);
float y = yPos + cos(angle) * 50;
float xx = x - (pow(sin(angle), 2) * 20) - pow(cos(angle / 2), 2) * 20;
float yy = y + noise(cos(offset + angle) * 2) * 20;
vertex(xx, yy);
// Put a point every 5 vertex
if (i % 5 == 0) {
strokeWeight(5);
point(xx, yy);
}
}
strokeWeight(2);
endShape();
}
/**
* Display multiple waves horizontally
*/
void horizontalWaves(int nLines, float vSize) {
// Rotate 90° (did this afterward instead of swaping x and y)
rotate(HALF_PI);
translate(0, -height);
float startY = height / 2 - vSize / 2;
// Draw the curves, vary the parameters to offset them
for (int i = 0; i < nLines; i++) {
float cycles = map(i, 0, nLines - 1, 2, 3);
float y = startY + i * (vSize / nLines);
float angle = map(i, 0, nLines, 0, TWO_PI);
float off = offset + cos(angle) * i * 0.05;
drawWave(50, cycles, off, y, 300);
}
}
void setup() {
size(500, 500);
}
void draw() {
background(255);
horizontalWaves(nLines, vSize);
offset -= 0.04;
}