Commit | Line | Data |
---|---|---|
e0cfbe20 | 1 | class SineSphere extends SCPattern { |
38712136 | 2 | private SawLFO yrot = new SawLFO(0, TWO_PI, 3000); |
e0cfbe20 AG |
3 | private SawLFO yrot2 = new SawLFO(0, -TWO_PI, 8000); |
4 | public final Projection sinespin; | |
5 | public final Projection sinespin2; | |
1d414e45 | 6 | private BasicParameter rotation = new BasicParameter("rotation", 0); |
a9aad043 | 7 | float modelrad = sqrt((model.xMax)*(model.xMax) + (model.yMax)*(model.yMax) + (model.zMax)*(model.zMax)); |
a9aad043 | 8 | Pick Sshape; |
7974acd6 | 9 | public final PVector P = new PVector(); |
a9aad043 | 10 | |
0b1785e3 | 11 | class Sphery { |
a9aad043 | 12 | float f1xcenter, f1ycenter, f1zcenter, f2xcenter , f2ycenter, f2zcenter; //second three are for an ellipse with two foci |
0b1785e3 AG |
13 | private SinLFO vibration; |
14 | private SinLFO surface; | |
15 | private SinLFO vx; | |
a9aad043 AG |
16 | private SinLFO xbounce; |
17 | public SinLFO ybounce; | |
18 | private SinLFO zbounce; | |
0b1785e3 | 19 | float vibration_min, vibration_max, vperiod; |
a9aad043 AG |
20 | public BasicParameter widthparameter; |
21 | public BasicParameter huespread; | |
22 | public BasicParameter bouncerate; | |
23 | public BasicParameter bounceamp; | |
7974acd6 | 24 | public final PVector circlecenter = new PVector(); |
a9aad043 AG |
25 | |
26 | public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float vibration_min, float vibration_max, float vperiod) | |
27 | { | |
0b1785e3 AG |
28 | this.f1xcenter = f1xcenter; |
29 | this.f1ycenter = f1ycenter; | |
30 | this.f1zcenter = f1zcenter; | |
31 | this.vibration_min = vibration_min; | |
32 | this.vibration_max = vibration_max; | |
33 | this.vperiod = vperiod; | |
1d414e45 AG |
34 | //addParameter(bounceamp = new BasicParameter("Amp", .5)); |
35 | //addParameter(bouncerate = new BasicParameter("Rate", .5)); //ybounce.modulateDurationBy(bouncerate); | |
a9aad043 | 36 | addParameter(widthparameter = new BasicParameter("Width", .1)); |
ffc523c0 | 37 | addParameter(huespread = new BasicParameter("Hue", .5, 10)); |
d8239019 | 38 | |
a9aad043 AG |
39 | addModulator( vx = new SinLFO(-4000, 10000, 100000)).trigger() ; |
40 | //addModulator(xbounce = new SinLFO(model.xMax/3, 2*model.yMax/3, 2000)).trigger(); | |
41 | addModulator(ybounce= new SinLFO(model.yMax/3, 2*model.yMax/3, 240000./lx.tempo.bpm())).trigger(); //ybounce.modulateDurationBy | |
42 | ||
43 | //addModulator(bounceamp); //ybounce.setMagnitude(bouncerate); | |
44 | addModulator( vibration = new SinLFO(vibration_min , vibration_max, 240000./lx.tempo.bpm())).trigger(); //vibration.modulateDurationBy(vx); | |
7974acd6 | 45 | |
a9aad043 AG |
46 | } |
47 | public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float f2xcenter, float f2ycenter, float f2zcenter, | |
48 | float vibration_min, float vibration_max, float vperiod) | |
38712136 | 49 | |
a9aad043 AG |
50 | { |
51 | this.f1xcenter = f1xcenter; | |
52 | this.f1ycenter = f1ycenter; | |
53 | this.f1zcenter = f1zcenter; | |
54 | this.f2xcenter = f2xcenter; | |
55 | this.f2ycenter = f2ycenter; | |
56 | this.f2zcenter = f2zcenter; | |
57 | this.vibration_min = vibration_min; | |
58 | this.vibration_max = vibration_max; | |
59 | this.vperiod = vperiod; | |
60 | //addModulator(xbounce = new SinLFO(model.xMax/3, 2*model.yMax/3, 2000)).trigger(); | |
61 | addModulator(ybounce).trigger(); | |
62 | addModulator( vibration = new SinLFO(vibration_min , vibration_max, lx.tempo.rampf())).trigger(); //vibration.modulateDurationBy(vx); | |
63 | addParameter(widthparameter = new BasicParameter("Width", .1)); | |
ffc523c0 | 64 | addParameter(huespread = new BasicParameter("Hue", .2)); |
a9aad043 AG |
65 | |
66 | } | |
67 | ||
68 | ||
69 | ||
70 | ||
71 | ||
72 | float distfromcirclecenter(float px, float py, float pz, float f1x, float f1y, float f1z) | |
73 | { | |
0b1785e3 AG |
74 | return dist(px, py, pz, f1x, f1y, f1z); |
75 | } | |
c2f643bd | 76 | //void updatespherey(deltaMs, ) |
55a56424 | 77 | |
e0cfbe20 | 78 | float quadrant(PVector q) { |
7b2faded AG |
79 | float qtheta = atan2( (q.x-f1xcenter) , (q.z - f1zcenter) ); |
80 | //println( "qtheta " + qtheta); | |
81 | ||
ffc523c0 | 82 | return map(qtheta, -PI/2, PI/2, 140, 240); |
e0cfbe20 AG |
83 | //if (q.x > f1xcenter ) {return 140 ;} |
84 | //else {return 250;} | |
55a56424 | 85 | } |
7974acd6 MS |
86 | color spheryvalue (PVector p, float f1xcenter, float f1ycenter, float f1zcenter) { |
87 | circlecenter.set(f1xcenter, f1ycenter, f1zcenter); | |
88 | ||
89 | // circlecenter = new PVector(f1xcenter, f1ycenter, f1zcenter); | |
a9aad043 | 90 | //switch(sShpape.cur() ) {} |
7974acd6 MS |
91 | |
92 | float b = max(0, 100 - 100*widthparameter.getValuef()*abs(p.dist(circlecenter) | |
93 | - vibration.getValuef() ) ); | |
94 | ||
95 | if (b <= 0) { | |
96 | return 0; | |
97 | } | |
98 | ||
99 | return lx.hsb( | |
100 | constrain(huespread.getValuef()*5*quadrant(p), 0, 360), | |
101 | 80, | |
102 | b | |
103 | ); | |
0b1785e3 | 104 | } |
a9aad043 AG |
105 | color ellipsevalue(float px, float py, float pz , float f1xc, float f1yc, float f1zc, float f2xc, float f2yc, float f2zc) |
106 | { | |
107 | //switch(sShpape.cur() ) {} | |
a41f334c | 108 | return lx.hsb(huespread.getValuef()*5*px, dist(model.xMax-px, model.yMax-py, model.zMax-pz, f1xc, f1yc, f1zc) , |
a9aad043 AG |
109 | max(0, 100 - 100*widthparameter.getValuef() * |
110 | abs( (dist(px, py, pz, f1xc, ybounce.getValuef(), f1zc) + | |
111 | (dist(px, py , pz, f2xc, ybounce.getValuef(), f2zc) ) )/2 | |
112 | - 1.2*vibration.getValuef() ) ) ) ; | |
0b1785e3 | 113 | } |
a9aad043 | 114 | |
d8239019 AG |
115 | void run(double deltaMs) { |
116 | float vv = vibration.getValuef(); | |
117 | float ybv = ybounce.getValuef(); | |
118 | ||
119 | } | |
0b1785e3 | 120 | |
a9aad043 AG |
121 | } |
122 | ||
123 | ||
0b1785e3 | 124 | final Sphery[] spherys; |
1d414e45 | 125 | |
a9aad043 AG |
126 | SineSphere(GLucose glucose) |
127 | { | |
0b1785e3 | 128 | super(glucose); |
d8239019 | 129 | sinespin = new Projection(model); |
e0cfbe20 | 130 | sinespin2 = new Projection(model); |
d8239019 | 131 | addModulator(yrot).trigger(); |
e0cfbe20 | 132 | addModulator(yrot2).trigger(); |
1d414e45 | 133 | addParameter(rotation); |
b30f14fd | 134 | //Sshape = addPick("Shape", , 1); |
a9aad043 AG |
135 | spherys = new Sphery[] { |
136 | new Sphery(model.xMax/4, model.yMax/2, model.zMax/2, modelrad/16, modelrad/8, 3000), | |
137 | new Sphery(.75*model.xMax, model.yMax/2, model.zMax/2, modelrad/20, modelrad/10, 2000), | |
138 | new Sphery(model.xMax/2, model.yMax/2, model.zMax/2, modelrad/4, modelrad/8, 2300), | |
e0cfbe20 AG |
139 | |
140 | new Sphery(.3*model.xMax, .4*model.yMax, .6*model.zMax, modelrad/16, modelrad/8, 4000), | |
141 | new Sphery(.75*model.xMax, model.yMax/2, model.zMax/2, modelrad/20, modelrad/10, 2000), | |
142 | new Sphery(model.xMax/2, model.yMax/2, model.zMax/2, modelrad/4, modelrad/8, 2300), | |
143 | ||
7974acd6 | 144 | }; |
0b1785e3 AG |
145 | } |
146 | ||
a9aad043 AG |
147 | // public void onParameterChanged(LXParameter parameter) |
148 | // { | |
e28f168c | 149 | |
e28f168c | 150 | |
a9aad043 AG |
151 | // for (Sphery s : spherys) { |
152 | // if (s == null) continue; | |
153 | // double bampv = s.bounceamp.getValue(); | |
154 | // double brv = s.bouncerate.getValue(); | |
155 | // double tempobounce = lx.tempo.bpm(); | |
156 | // if (parameter == s.bounceamp) | |
157 | // { | |
158 | // s.ybounce.setRange(bampv*model.yMax/3 , bampv*2*model.yMax/3, brv); | |
159 | // } | |
160 | // else if ( parameter == s.bouncerate ) | |
161 | // { | |
162 | // s.ybounce.setDuration(120000./tempobounce); | |
163 | // } | |
164 | // } | |
165 | // } | |
e28f168c | 166 | |
1d414e45 | 167 | public void run( double deltaMs) { |
a9aad043 AG |
168 | float t = lx.tempo.rampf(); |
169 | float bpm = lx.tempo.bpmf(); | |
55a56424 AG |
170 | spherys[0].run(deltaMs); |
171 | spherys[1].run(deltaMs); | |
172 | spherys[2].run(deltaMs); | |
e0cfbe20 AG |
173 | spherys[3].run(deltaMs); |
174 | ||
d8239019 | 175 | sinespin.reset(model) |
e0cfbe20 AG |
176 | |
177 | ||
1d414e45 | 178 | // Translate so the center of the car is the origin, offset |
38712136 AG |
179 | .translateCenter(model, 0, 0, 0) |
180 | // .scale(1.3,1.3,1.3) | |
1d414e45 | 181 | // Rotate around the origin (now the center of the car) about an y-vector |
38712136 AG |
182 | .rotate(yrot.getValuef(), 0, 1 , 0) |
183 | .translate(model.cx, model.cy, model.cz); | |
1d414e45 | 184 | |
d8239019 | 185 | |
e0cfbe20 | 186 | |
1d414e45 | 187 | |
d8239019 | 188 | |
38712136 AG |
189 | for (Coord p: sinespin) |
190 | // for (Point p: model.points) | |
1d414e45 | 191 | { |
7974acd6 MS |
192 | P.set(p.x, p.y, p.z); |
193 | // PVector P = new PVector(p.x, p.y, p.z); | |
194 | color c = #000000; | |
195 | c = blendIfColor(c, spherys[1].spheryvalue(P, .75*model.xMax, model.yMax/2, model.zMax/2), ADD); | |
196 | c = blendIfColor(c, spherys[0].spheryvalue(P, model.xMax/4, model.yMax/4, model.zMax/2), ADD); | |
197 | c = blendIfColor(c, spherys[2].spheryvalue(P, model.xMax/2, model.yMax/2, model.zMax/2),ADD); | |
e0cfbe20 | 198 | |
d8239019 | 199 | |
7974acd6 | 200 | colors[p.index] = c; |
e0cfbe20 | 201 | |
d8239019 | 202 | |
e0cfbe20 AG |
203 | } |
204 | sinespin2.reset(model). | |
205 | translateCenter(model,0,0,0). | |
206 | rotate(yrot2.getValuef(), 0, 1, 0). | |
207 | translate(model.cx,model.cy,model.cz); | |
208 | ||
209 | for (Coord p: sinespin2) | |
210 | { color c = 0; | |
7974acd6 MS |
211 | // PVector P = new PVector(p.x, p.y, p.z); |
212 | P.set(p.x, p.y, p.z); | |
213 | c = blendIfColor(c, spherys[3].spheryvalue(P, .3*model.xMax, .7*model.yMax, .6*model.zMax),ADD); | |
7b2faded | 214 | |
7974acd6 | 215 | colors[p.index] = blendIfColor(colors[p.index], c , ADD); |
e0cfbe20 AG |
216 | |
217 | } | |
218 | ||
e28f168c | 219 | |
e27a8652 | 220 | |
7974acd6 MS |
221 | } |
222 | ||
223 | color blendIfColor(color c1, color c2, int mode) { | |
224 | if (c2 != 0) { | |
225 | return blendColor(c1, c2, mode); | |
226 | } | |
227 | return c1; | |
a9aad043 | 228 | } |
e27a8652 | 229 | |
a9aad043 AG |
230 | |
231 | // color c = 0; | |
232 | // c = blendColor(c, spherys[3].ellipsevalue(Px.x, Px.y, Px.z, model.xMax/4, model.yMax/4, model.zMax/4, 3*model.xMax/4, 3*model.yMax/4, 3*model.zMax/4),ADD); | |
233 | // return c; | |
234 | // } | |
a41f334c | 235 | // return lx.hsb(0,0,0); |
a9aad043 AG |
236 | // // else if(spheremode ==2) |
237 | // { color c = 0; | |
a41f334c | 238 | // return lx.hsb(CalcCone( (xyz by = new xyz(0,spherys[2].ybounce.getValuef(),0) ), Px, mid) ); |
a9aad043 AG |
239 | |
240 | // } | |
241 | ||
242 | ||
d8239019 | 243 | // } |
a9aad043 AG |
244 | |
245 | } | |
246 | ||
5bc92bc2 | 247 | class CubeCurl extends SCPattern{ |
b30f14fd AG |
248 | float CH, CW, diag; |
249 | ArrayList<PVector> cubeorigin = new ArrayList<PVector>(); | |
250 | ArrayList<PVector> centerlist = new ArrayList<PVector>(); | |
5bc92bc2 AG |
251 | private SinLFO curl = new SinLFO(0, Cube.EDGE_HEIGHT, 5000 ); |
252 | ||
253 | private SinLFO bg = new SinLFO(180, 220, 3000); | |
254 | ||
255 | CubeCurl(GLucose glucose){ | |
256 | super(glucose); | |
257 | addModulator(curl).trigger(); | |
258 | addModulator(bg).trigger(); | |
7c7625ec AG |
259 | this.CH = Cube.EDGE_HEIGHT; |
260 | this.CW = Cube.EDGE_WIDTH; | |
f1370a0b | 261 | this.diag = sqrt(CW*CW + CW*CW); |
b30f14fd | 262 | |
7c7625ec | 263 | |
b30f14fd | 264 | ArrayList<PVector> centerlistrelative = new ArrayList<PVector>(); |
7c7625ec | 265 | for (int i = 0; i < model.cubes.size(); i++){ |
b30f14fd AG |
266 | Cube a = model.cubes.get(i); |
267 | cubeorigin.add(new PVector(a.x, a.y, a.z)); | |
e0cfbe20 | 268 | centerlist.add(new PVector(a.cx, a.cy, a.cz) ); |
b30f14fd AG |
269 | |
270 | } | |
5bc92bc2 AG |
271 | |
272 | } | |
7c7625ec AG |
273 | //there is definitely a better way of doing this! |
274 | PVector centerofcube(int i) { | |
275 | Cube c = model.cubes.get(i); | |
f1370a0b AG |
276 | |
277 | println(" cube #: " + i + " c.x " + c.x + " c.y " + c.y + " c.z " + c.z ); | |
1d414e45 AG |
278 | // PVector cubeangle = new PVector(c.rx, c.ry, c.rz); |
279 | println("raw x angle: " + c.rx + "raw y angle: " + c.ry + "raw z angle: " + c.rz); | |
f1370a0b AG |
280 | PVector cubecenter = new PVector(c.x + CW/2, c.y + CH/2, c.z + CW/2); |
281 | println("cubecenter unrotated: " + cubecenter.x + " " +cubecenter.y + " " +cubecenter.z ); | |
1d414e45 | 282 | PVector centerrot = new PVector(cos(c.rx)*CW/2 - sin(c.rx)*CW/2, cubecenter.y, cos(c.rz)*CW/2 + sin(c.rz)*CW/2); |
f1370a0b | 283 | // nCos*(y-o.y) - nSin*(z-o.z) + o.y |
1d414e45 | 284 | cubecenter = PVector.add(new PVector(c.x, c.y, c.z), centerrot); |
f1370a0b AG |
285 | println( " cubecenter.x " + cubecenter.x + " cubecenter.y " + cubecenter.y + " cubecenter.z " + cubecenter.z + " "); |
286 | ||
287 | ||
b30f14fd | 288 | return cubecenter; |
7c7625ec AG |
289 | } |
290 | ||
5bc92bc2 AG |
291 | |
292 | void run(double deltaMs){ | |
293 | for (int i =0; i < model.cubes.size(); i++) { | |
294 | Cube c = model.cubes.get(i); | |
295 | float cfloor = c.y; | |
296 | ||
f1370a0b | 297 | // if (i%3 == 0){ |
5bc92bc2 | 298 | |
f1370a0b AG |
299 | // for (Point p : c.points ){ |
300 | // // colors[p.index]=color(0,0,0); | |
301 | // //float dif = (p.y - c.y); | |
302 | // //colors[p.index] = color( bg.getValuef() , 80 , dif < curl.getValuef() ? 80 : 0, ADD); | |
303 | // } | |
304 | // } | |
5bc92bc2 | 305 | |
f1370a0b | 306 | // else if (i%3 == 1) { |
5bc92bc2 | 307 | |
f1370a0b AG |
308 | // for (Point p: c.points){ |
309 | // colors[p.index]=color(0,0,0); | |
310 | // float dif = (p.y - c.y); | |
311 | // // colors[p.index] = | |
312 | // // color(bg.getValuef(), | |
313 | // // map(curl.getValuef(), 0, Cube.EDGE_HEIGHT, 20, 100), | |
314 | // // 100 - 10*abs(dif - curl.getValuef()), ADD ); | |
315 | // } | |
316 | // } | |
317 | // else if (i%3 == 2){ | |
b30f14fd | 318 | // centerlist[i].sub(cubeorigin(i); |
5bc92bc2 | 319 | for (Point p: c.points) { |
b30f14fd | 320 | PVector pv = new PVector(p.x, p.y, p.z); |
f1370a0b | 321 | colors[p.index] =color( constrain(4* pv.dist(centerlist.get(i)), 0, 360) , 50, 100 ); |
b30f14fd | 322 | // colors[p.index] =color(constrain(centerlist[i].x, 0, 360), constrain(centerlist[i].y, 0, 100), ); |
5bc92bc2 AG |
323 | |
324 | ||
b30f14fd | 325 | } |
5bc92bc2 AG |
326 | |
327 | ||
f1370a0b | 328 | //} |
5bc92bc2 AG |
329 | |
330 | } | |
331 | } | |
332 | } | |
333 | ||
a9aad043 AG |
334 | class HueTestHSB extends SCPattern{ |
335 | BasicParameter HueT = new BasicParameter("Hue", .5); | |
336 | BasicParameter SatT = new BasicParameter("Sat", .5); | |
337 | BasicParameter BriT = new BasicParameter("Bright", .5); | |
338 | ||
339 | HueTestHSB(GLucose glucose) { | |
340 | super(glucose); | |
341 | addParameter(HueT); | |
342 | addParameter(SatT); | |
343 | addParameter(BriT); | |
344 | } | |
345 | void run(double deltaMs){ | |
346 | ||
347 | for (Point p : model.points) { | |
348 | color c = 0; | |
a41f334c | 349 | c = blendColor(c, lx.hsb(360*HueT.getValuef(), 100*SatT.getValuef(), 100*BriT.getValuef()), ADD); |
a9aad043 AG |
350 | colors[p.index]= c; |
351 | } | |
352 | int now= millis(); | |
353 | if (now % 1000 <= 20) | |
354 | { | |
355 | println("Hue: " + 360*HueT.getValuef() + "Sat: " + 100*SatT.getValuef() + "Bright: " + 100*BriT.getValuef()); | |
356 | } | |
357 | } | |
0b1785e3 | 358 | |
a41f334c | 359 | } |