-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathday_4.pde
67 lines (54 loc) · 1.41 KB
/
day_4.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
import java.util.List;
float margin = 50;
// Rössler attractor parameters
// https://en.wikipedia.org/wiki/R%C3%B6ssler_attractor
int iterations = 5000;
float a = 0.2;
float b = 0.2;
float c = 5.7;
float range = 25;
float h = 0.001;
int substeps = 50;
int cameraDist = 40;
int maxPoints = 4000;
float angle = 0;
List<PVector> points;
void setup() {
size(500, 500, P3D);
points = new ArrayList<PVector>();
// Precompute the attractor points
float x = 1;
float y = 1;
float z = 1;
for (int i = 0; i < iterations; i++) {
points.add(new PVector(x, y, z));
for (int j = 0; j < substeps; j++) {
float tempx = x;
x += h * (- y - z);
y += h * (tempx + a * y);
z += h * (b + z * (tempx - c));
}
}
}
void draw() {
background(255);
// Place the camera in 3d space with turntable
perspective(PI/3.0, width/height, 1, 200);
camera(cos(angle) * cameraDist, sin(angle) * cameraDist, cameraDist * 0.7, 0, 0, 10, 0, 0, -1);
// The points are drawn in order and disapear
int begin = 0;
int end = points.size();
if (angle >= TWO_PI) {
begin = int(((angle - TWO_PI) / TWO_PI) * points.size());
} else {
end = int((angle / TWO_PI) * points.size());
}
// Display the points
strokeWeight(2);
for (int i = begin; i < end; i++) {
PVector p = points.get(i);
stroke(map(i, begin, end, 0, 255));
point(p.x, p.y, p.z);
}
angle += 0.01;
}