-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstellation.pde
153 lines (129 loc) · 3.36 KB
/
constellation.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
color[] palette = {#FFFF73, #FFFF99, #FFFFBF};
PVector origin = new PVector(0, 0);
float rebound = 0.9;
float decay = 0.8;
float speed = 15;
float globalPhase = 0;
class Constellation {
private final ArrayList<CellestialBody> bodies;
private float phase;
private float phaseAddition;
private float phaseAcc;
Constellation(int size, int sizeOfBodies) {
this.bodies = new ArrayList();
this.phase = 0;
this.phaseAddition = 0;
this.phaseAcc = 0;
for (int i = 0; i < size; i++) {
float x = random(-width * 1.1, width * 1.1);
float y = random(-height * 1.1, height * 1.1);
bodies.add(new CellestialBody(sizeOfBodies, new PVector(x, y), #1A9FF9, random(0, TWO_PI)));
}
}
void draw() {
pushMatrix();
translate(width / 2, // + (sin(phase * 4) * width/8),
height / 2); // + (cos(phase * 6) * height/8));
rotate(phase);
for (CellestialBody body : bodies) {
body.draw();
}
popMatrix();
}
void update() {
phase += (0.01 * (1 + phaseAcc));
phaseAcc *= decay;
for (CellestialBody body : bodies) {
body.update();
}
}
void contract() {
for (CellestialBody body : bodies) {
body.pushTo(origin);
}
}
void expand() {
for (CellestialBody body : bodies) {
body.pushFrom(origin);
}
}
void awaken(float amount) {
for (CellestialBody body : bodies) {
body.awaken(amount);
}
}
void speedUp(float amount) {
this.phaseAcc += amount;
}
}
class CellestialBody {
private color c;
private int size;
private PVector position;
private PVector displacement;
private PVector acc;
private float phase;
private float baseAwareness;
private float wokeness;
private float wokeacc;
CellestialBody(int size, PVector position, color c, float phase) {
this.size = size;
this.position = position;
this.displacement = new PVector(0, 0);
this.acc = new PVector(0, 0);
this.c = c;
this.phase = phase;
this.baseAwareness = 0.2;
this.wokeness = 0;
this.wokeacc = 0;
}
void draw() {
pushMatrix();
translate(x(), y());
noStroke();
fill(c, map(sin(phase), -1, 1, map(woke(), 0, 1, 0, 50), map(woke(), 0, 1, 50, 255)));
float currentSize = size();
ellipse(0, 0, currentSize, currentSize);
popMatrix();
}
void update() {
phase += 0.1;
phase = phase % TWO_PI;
if (displacement.mag() < position.mag()) {
displacement.add(acc);
}
displacement.mult(rebound);
acc.mult(decay);
wokeness = min(1 - baseAwareness, wokeness + (wokeacc * .5));
wokeness *= rebound;
wokeacc *= decay;
}
private float size() {
return size + breathe();
}
private float x() {
return position.x + displacement.x + (sin(phase) * 10) + (sin(phase * 10) * woke() * 2);
}
private float y() {
return position.y + displacement.y + (sin(phase + PI/4) * 10) + (sin(phase * 10) * woke() * 2);
}
float breathe() {
return sin(phase) * 2;
}
float woke() {
return baseAwareness + wokeness;
}
void pushTo(PVector to) {
acc = PVector.sub(to, position);
acc.normalize();
acc.mult(speed);
}
void pushFrom(PVector from) {
acc = PVector.sub(position, from);
acc.normalize();
acc.mult(speed);
}
void awaken(float amount) {
wokeacc = amount * (1 - baseAwareness);
}
}