Switch to threaded mode by default, run engine at 120FPS
[SugarCubes.git] / JackieBavaro.pde
CommitLineData
cc9e8c8b 1import java.util.Iterator;
37ab5878 2class JackieSquares extends SCPattern {
3 private BasicParameter rateParameter = new BasicParameter("RATE", 0.25);
37ab5878 4 private BasicParameter attackParameter = new BasicParameter("ATTK", 0.3);
5 private BasicParameter decayParameter = new BasicParameter("DECAY", 0.2);
6 private BasicParameter saturationParameter = new BasicParameter("SAT", 0.7);
7
8 SinLFO hueMod = new SinLFO(0, 360, 4000);
9 SinLFO spreadMod = new SinLFO(1, 10, 8000);
10
11
12 class FaceFlash {
13 Face f;
14 float value;
15 float hue;
16 boolean hasPeaked;
17
18 FaceFlash(int n) {
19 f = model.faces.get(n % model.faces.size());
20 hue = random(360);
21 boolean infiniteAttack = (attackParameter.getValuef() > 0.999);
22 hasPeaked = infiniteAttack;
23 value = (infiniteAttack ? 1 : 0);
24 }
25
26 // returns TRUE if this should die
27 boolean age(double ms) {
28 if (!hasPeaked) {
29 value = value + (float) (ms / 1000.0f * ((attackParameter.getValuef() + 0.01) * 5));
30 if (value >= 1.0) {
31 value = 1.0;
32 hasPeaked = true;
33 }
34 return false;
35 } else {
36 value = value - (float) (ms / 1000.0f * ((decayParameter.getValuef() + 0.01) * 10));
37 return value <= 0;
38 }
39 }
40 }
41
42 private float leftoverMs = 0;
43 private List<FaceFlash> flashes;
44 private int faceNum = 0;
45
dde75983
MS
46 public JackieSquares(LX lx) {
47 super(lx);
37ab5878 48 addParameter(rateParameter);
49 addParameter(attackParameter);
50 addParameter(decayParameter);
51 addParameter(saturationParameter);
52 addModulator(hueMod).trigger();
53 addModulator(spreadMod).trigger();
54
55 flashes = new LinkedList<FaceFlash>();
56 }
57
58 public void run(double deltaMs) {
59 leftoverMs += deltaMs;
60 float msPerFlash = 1000 / ((rateParameter.getValuef() + .01) * 100);
61 while (leftoverMs > msPerFlash) {
62 leftoverMs -= msPerFlash;
63 faceNum += int(spreadMod.getValuef());
64 flashes.add(new FaceFlash(faceNum));
65 }
66
67 for (LXPoint p : model.points) {
68 colors[p.index] = 0;
69 }
70
71 for (FaceFlash flash : flashes) {
72 float hue = (hueMod.getValuef() + flash.hue) % 360.0;
73 color c = lx.hsb(hue, saturationParameter.getValuef() * 100, (flash.value) * 100);
74 for (LXPoint p : flash.f.points) {
75 colors[p.index] = c;
76 }
77 }
78
79 Iterator<FaceFlash> i = flashes.iterator();
80 while (i.hasNext()) {
81 FaceFlash flash = i.next();
82 boolean dead = flash.age(deltaMs);
83 if (dead) {
84 i.remove();
85 }
86 }
87 }
88}
89
4a60ba58 90
91class JackieLines extends SCPattern {
92 private BasicParameter rateParameter = new BasicParameter("RATE", 0.25);
93 private BasicParameter attackParameter = new BasicParameter("ATTK", 0.3);
94 private BasicParameter decayParameter = new BasicParameter("DECAY", 0.2);
95 private BasicParameter saturationParameter = new BasicParameter("SAT", 0.7);
96
97 SinLFO hueMod = new SinLFO(0, 360, 4000);
98 SinLFO spreadMod = new SinLFO(1, 10, 8000);
99
100
101 class StripFlash {
102 Strip f;
103 float value;
104 float hue;
105 boolean hasPeaked;
106
107 StripFlash(int n) {
108 f = model.strips.get(n % model.strips.size());
109 hue = random(360);
110 boolean infiniteAttack = (attackParameter.getValuef() > 0.999);
111 hasPeaked = infiniteAttack;
112 value = (infiniteAttack ? 1 : 0);
113 }
114
115 // returns TRUE if this should die
116 boolean age(double ms) {
117 if (!hasPeaked) {
118 value = value + (float) (ms / 1000.0f * ((attackParameter.getValuef() + 0.01) * 5));
119 if (value >= 1.0) {
120 value = 1.0;
121 hasPeaked = true;
122 }
123 return false;
124 } else {
125 value = value - (float) (ms / 1000.0f * ((decayParameter.getValuef() + 0.01) * 10));
126 return value <= 0;
127 }
128 }
129 }
130
131 private float leftoverMs = 0;
132 private List<StripFlash> flashes;
133 private int stripNum = 0;
134
dde75983
MS
135 public JackieLines(LX lx) {
136 super(lx);
4a60ba58 137 addParameter(rateParameter);
138 addParameter(attackParameter);
139 addParameter(decayParameter);
140 addParameter(saturationParameter);
141 addModulator(hueMod).trigger();
142 addModulator(spreadMod).trigger();
143
144 flashes = new LinkedList<StripFlash>();
145 }
146
147 public void run(double deltaMs) {
148 leftoverMs += deltaMs;
149 float msPerFlash = 1000 / ((rateParameter.getValuef() + .01) * 100);
150 while (leftoverMs > msPerFlash) {
151 leftoverMs -= msPerFlash;
152 stripNum += int(spreadMod.getValuef());
153 flashes.add(new StripFlash(stripNum));
154 }
155
156 for (LXPoint p : model.points) {
157 colors[p.index] = 0;
158 }
159
160 for (StripFlash flash : flashes) {
161 float hue = (hueMod.getValuef() + flash.hue) % 360.0;
162 color c = lx.hsb(hue, saturationParameter.getValuef() * 100, (flash.value) * 100);
163 for (LXPoint p : flash.f.points) {
164 colors[p.index] = c;
165 }
166 }
167
168 Iterator<StripFlash> i = flashes.iterator();
169 while (i.hasNext()) {
170 StripFlash flash = i.next();
171 boolean dead = flash.age(deltaMs);
172 if (dead) {
173 i.remove();
174 }
175 }
176 }
177}
178
179
180
181class JackieDots extends SCPattern {
182 private BasicParameter rateParameter = new BasicParameter("RATE", 0.15);
183 private BasicParameter attackParameter = new BasicParameter("ATTK", 0.3);
184 private BasicParameter decayParameter = new BasicParameter("DECAY", 0.2);
185 private BasicParameter saturationParameter = new BasicParameter("SAT", 0.7);
186
187 SinLFO hueMod = new SinLFO(0, 360, 4000);
188 SinLFO spreadMod = new SinLFO(1, 10, 16000);
189
190
191 class PointFlash {
192 LXPoint f;
193 float value;
194 float hue;
195 boolean hasPeaked;
196
197 PointFlash(int n) {
198 f = model.points.get(n % model.points.size());
199 hue = random(360);
200 boolean infiniteAttack = (attackParameter.getValuef() > 0.999);
201 hasPeaked = infiniteAttack;
202 value = (infiniteAttack ? 1 : 0);
203 }
204
205 // returns TRUE if this should die
206 boolean age(double ms) {
207 if (!hasPeaked) {
208 value = value + (float) (ms / 1000.0f * ((attackParameter.getValuef() + 0.01) * 5));
209 if (value >= 1.0) {
210 value = 1.0;
211 hasPeaked = true;
212 }
213 return false;
214 } else {
215 value = value - (float) (ms / 1000.0f * ((decayParameter.getValuef() + 0.01) * 10));
216 return value <= 0;
217 }
218 }
219 }
220
221 private float leftoverMs = 0;
222 private List<PointFlash> flashes;
223 private int pointNum = 0;
224
dde75983
MS
225 public JackieDots(LX lx) {
226 super(lx);
4a60ba58 227 addParameter(rateParameter);
228 addParameter(attackParameter);
229 addParameter(decayParameter);
230 addParameter(saturationParameter);
231 addModulator(hueMod).trigger();
232 addModulator(spreadMod).trigger();
233
234 flashes = new LinkedList<PointFlash>();
235 }
236
237 public void run(double deltaMs) {
238 leftoverMs += deltaMs;
239 float msPerFlash = 1000 / ((rateParameter.getValuef() + .01) * 5000);
240 while (leftoverMs > msPerFlash) {
241 leftoverMs -= msPerFlash;
242 pointNum += int(spreadMod.getValuef());
243 flashes.add(new PointFlash(pointNum));
244 }
245
246 for (LXPoint p : model.points) {
247 colors[p.index] = 0;
248 }
249
250 for (PointFlash flash : flashes) {
251 float hue = (hueMod.getValuef() + flash.hue) % 360.0;
252 color c = lx.hsb(hue, saturationParameter.getValuef() * 100, (flash.value) * 100);
253 colors[flash.f.index] = c;
254 }
255
256 Iterator<PointFlash> i = flashes.iterator();
257 while (i.hasNext()) {
258 PointFlash flash = i.next();
259 boolean dead = flash.age(deltaMs);
260 if (dead) {
261 i.remove();
262 }
263 }
264 }
265}
266