-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDomeStarPermutatingRect.pde
112 lines (95 loc) · 2.96 KB
/
DomeStarPermutatingRect.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
private class Permutation {
/**
* Represents a value that changes over time, in this case with each call
*/
float value;
float delta;
float multiplier;
float min;
float max;
public Permutation(float value, float delta, float multiplier) {
this.value = value;
this.delta = delta;
this.multiplier = multiplier;
this.min = -Float.MAX_VALUE;
this.max = Float.MAX_VALUE;
}
public Permutation(float value, float delta, float multiplier, float min, float max) {
this.value = value;
this.delta = delta;
this.multiplier = multiplier;
this.min = min;
this.max = max;
}
public void permutate() {
value = (value + delta) * multiplier;
while (value > this.max)
value -= this.max;
while (value < this.min)
value += this.max;
}
}
DomeStarMap map;
LEDDisplay dome;
Permutation rotation = new Permutation(0, PI/128, 1, 0, 180);
Permutation velocity = new Permutation(PI/128, PI/102400, 1);
void setup() {
size(360,360);
background(0);
dome = new LEDDisplay(this, 40, 160, true, "localhost", 58082);
map = new DomeStarMap();
colorMode(HSB);
noFill();
rectMode(CENTER);
strokeWeight(8);
}
void permutatingRect(Permutation size, Permutation rotation, Permutation hue,
Permutation saturation, Permutation brightness,
Permutation count)
{
while (count.value > 0) {
// Shoot a bright rect through every so often.. Kinda hacky.
if ((frameCount / 4) % 24 == count.value)
stroke(hue.value, saturation.value, 254, 255);
else
stroke(hue.value, saturation.value, brightness.value, 127);
// Draw our rect
pushMatrix();
rotate(rotation.value);
rect(0, 0, size.value, size.value);
popMatrix();
// Permutate all our values
size.permutate();
rotation.permutate();
hue.permutate();
saturation.permutate();
brightness.permutate();
count.permutate();
}
}
void draw() {
// Our base rotation delta changes over time so that we see the patterns change
// We bounce betweeen PI/64 and PI/128 rotation deltas to keep it subtle.
velocity.permutate();
rotation.delta = velocity.value;
rotation.permutate();
if (velocity.value > PI/64 || velocity.value < PI/128) {
velocity.delta = -velocity.delta;
}
background(0);
pushMatrix();
translate(180,180);
if (frameCount % 100 == 0) {
println(rotation.value);
}
permutatingRect(
new Permutation(476, -34, 1), // Size, from outside going in
new Permutation(rotation.value, PI/16, 1.025), // Rotation, PI/16 * 103.33%
new Permutation(127, 0, 1), // Hue, static for now
new Permutation(191, 0, 1), // Saturation, static for now
new Permutation(254, -8, 1, 0, 255), // Brightness, toward dark, capped
new Permutation(14, -1, 1) // Count, 14
);
popMatrix();
dome.sendData(map.applyMap());
}