-
Notifications
You must be signed in to change notification settings - Fork 2
/
day_5.pde
54 lines (43 loc) · 1.19 KB
/
day_5.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
import java.util.List;
float margin = 50;
float noiseDepth = 0;
int pointSeparation = 3;
List<PVector> boids;
void setup() {
size(500, 500);
background(255);
boids = new ArrayList<PVector>();
// Create boids on the grid
for (float x = margin; x < width - margin; x+=pointSeparation) {
for (float y = margin; y < height - margin; y+=pointSeparation) {
boids.add(new PVector(x, y));
}
}
}
void draw() {
// Vary the brightness with time
stroke((noiseDepth / TWO_PI) * 255, 10);
// Go through every boid
for (PVector boid : boids) {
// Compute 2d noise with the depth as 3rd dimension
float noise = noise(boid.x / width * 5, boid.y / width * 5, noiseDepth);
// Compute the vector force from that noise value
PVector force = PVector.fromAngle(noise * TWO_PI).mult(0.5);
boid.add(force);
// Prevent boids from escaping the box
if (boid.x < margin) {
boid.x = width - margin;
}
if (boid.x > width - margin) {
boid.x = margin;
}
if (boid.y < margin) {
boid.y = height - margin;
}
if (boid.y > height - margin) {
boid.y = margin;
}
point(boid.x, boid.y);
}
noiseDepth += 0.01;
}