-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAttractor.pde
108 lines (92 loc) · 2.36 KB
/
Attractor.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
class AttractorPt {
PVector pos;
color col;
AttractorPt(PVector p, color c) {
pos = p;
col = c;
}
}
class Attractor {
String name;
int maxIter = 50000; // default number of iterations
PVector lastPt;
float sP = 1; // scale parameter
float magFactor = 1; // default magnification factor for points
float adjX = 0;
float adjY = 0;
float adjZ = 0;
PVector colorIndex;
AttractorPt[] pts = {};
PVector minPt;
PVector maxPt;
float colorStep = 0.00008;
float ptRadius = 1;
Attractor() {
colorIndex = new PVector(random(10), random(10), random(10));
}
void genPts() {
pts = new AttractorPt[maxIter];
minPt = lastPt.get();
maxPt = lastPt.get();
PVector pos;
for (int i = 0; i < maxIter; ++i) {
pos = nextPt();
color col = nextColor();
setMinMax(minPt, maxPt, pos);
pts[i] = new AttractorPt(pos, col);
}
}
// stub, should be overridden
PVector getDelta() { return new PVector(0, 0, 0); }
PVector nextPt() {
PVector delta = getDelta();
float x = lastPt.x + sP * delta.x;
float y = lastPt.y + sP * delta.y;
float z = lastPt.z + sP * delta.z;
PVector nextPt = new PVector(x, y, z);
lastPt = nextPt;
return nextPt;
}
color nextColor() {
colorIndex.add(colorStep, colorStep, colorStep);
return color(convNoisePos(colorIndex.x), convNoisePos(colorIndex.y), convNoisePos(colorIndex.z));
}
float convNoisePos(float noiseInd) {
return noise(noiseInd) * 255;
}
void setMinMax(PVector min, PVector max, PVector pt) {
util.calcVecMin(min, pt);
util.calcVecMax(max, pt);
}
void draw() {
noStroke();
pushMatrix();
translate(width / 2 + adjX, height / 2 + adjY, 0);
rotateY(sin(radians(frameCount * 2)) * PI / 2);
translate(0, 0, adjZ); // I think doing this after the rotation helps
for (int i = 0, l = pts.length; i < l; ++i) {
drawPt(pts[i]);
}
popMatrix();
}
void drawPt(AttractorPt pt) {
pushMatrix();
translate(pt.pos.x * magFactor, pt.pos.y * magFactor, pt.pos.z * magFactor);
fill(pt.col);
box(ptRadius, ptRadius, ptRadius);
popMatrix();
}
// stub, should be overridden
String[] getParamsDisplay() { return new String[0]; }
void drawParams() {
// add parameter labels
fill(255);
textSize(14);
int xPos = width - 100;
int yOff = 20;
String[] dispParams = getParamsDisplay();
for (int i = 0, len = dispParams.length; i < len; ++i) {
text(dispParams[i], xPos, yOff * (i + 1));
}
}
}