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