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; | |
9fa29818 | 9 | public final LXProjection sinespin; |
09437b3e | 10 | public final LXProjection sinespin2; |
a9aad043 | 11 | float modelrad = sqrt((model.xMax)*(model.xMax) + (model.yMax)*(model.yMax) + (model.zMax)*(model.zMax)); |
a9aad043 | 12 | Pick Sshape; |
09437b3e AG |
13 | |
14 | //to-do: how to sync all hues across sphery's via one basicparameter | |
15 | //public BasicParameter huespread = new BasicParameter("HueSpread", 180, 360); | |
16 | public BasicParameter rotationx = new BasicParameter("rotx", 0, 0, 1 ); | |
17 | public BasicParameter rotationy = new BasicParameter("roty", 1, 0, 1); | |
18 | public BasicParameter rotationz = new BasicParameter("rotz", 0, 0, 1); | |
19 | ||
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); |
9fa29818 | 163 | sinespin = new LXProjection(model); |
09437b3e | 164 | sinespin2 = new LXProjection(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(); | |
09f7f5df | 209 | //spherys[0].run(deltaMs); |
a9aad043 AG |
210 | //spherys[1].run(deltaMs); |
211 | //spherys[2].run(deltaMs); | |
d8239019 | 212 | //spherys[3].run(deltaMs);] |
2bb56822 | 213 | sinespin.reset() |
09437b3e AG |
214 | .center() |
215 | // .scale(1.3,1.3,1.3) | |
216 | // Rotate around the origin (now the center of the car) about an y-vector | |
217 | .rotate(yrot.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef()) | |
218 | .translate(model.cx, model.cy, model.cz); | |
1c44211b AG |
219 | switch (pitch) |
220 | { | |
221 | case 53: t = .5*t; bpm = .5*bpm; break; | |
222 | ||
223 | case 54: t = t; bpm = bpm; break; | |
224 | ||
225 | case 55: t = 2*t; bpm = 2*bpm; break; | |
226 | ||
227 | default: t= t; bpm = bpm; | |
09437b3e | 228 | } |
1c44211b | 229 | |
09437b3e | 230 | |
1c44211b AG |
231 | |
232 | for ( Sphery s: spherys){ | |
233 | s.setVibrationPeriod(480000/bpm); | |
e3da2932 | 234 | s.vibration.setBasis(t); |
1c44211b | 235 | } |
09437b3e | 236 | sinespin.reset() |
e0cfbe20 AG |
237 | |
238 | ||
1d414e45 | 239 | // Translate so the center of the car is the origin, offset |
09437b3e | 240 | .center() |
38712136 | 241 | // .scale(1.3,1.3,1.3) |
1d414e45 | 242 | // Rotate around the origin (now the center of the car) about an y-vector |
e3da2932 | 243 | .rotate(yrot.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef()) |
38712136 | 244 | .translate(model.cx, model.cy, model.cz); |
1d414e45 | 245 | |
d8239019 | 246 | |
e0cfbe20 | 247 | |
1d414e45 | 248 | |
d8239019 | 249 | |
09437b3e | 250 | for (LXVector p: sinespin) |
38712136 | 251 | // for (Point p: model.points) |
1d414e45 | 252 | { |
7974acd6 MS |
253 | P.set(p.x, p.y, p.z); |
254 | // PVector P = new PVector(p.x, p.y, p.z); | |
255 | color c = #000000; | |
256 | c = blendIfColor(c, spherys[1].spheryvalue(P, .75*model.xMax, model.yMax/2, model.zMax/2), ADD); | |
257 | c = blendIfColor(c, spherys[0].spheryvalue(P, model.xMax/4, model.yMax/4, model.zMax/2), ADD); | |
258 | c = blendIfColor(c, spherys[2].spheryvalue(P, model.xMax/2, model.yMax/2, model.zMax/2),ADD); | |
e0cfbe20 | 259 | |
d8239019 | 260 | |
7974acd6 | 261 | colors[p.index] = c; |
e0cfbe20 | 262 | |
d8239019 | 263 | |
e0cfbe20 | 264 | } |
09437b3e AG |
265 | sinespin2.reset() |
266 | .center() | |
267 | .rotate(yrot.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef()) | |
268 | .translate(model.cx,model.cy,model.cz); | |
e0cfbe20 | 269 | |
09437b3e | 270 | for (LXVector p: sinespin2) |
e0cfbe20 | 271 | { color c = 0; |
7974acd6 MS |
272 | // PVector P = new PVector(p.x, p.y, p.z); |
273 | P.set(p.x, p.y, p.z); | |
274 | c = blendIfColor(c, spherys[3].spheryvalue(P, .3*model.xMax, .7*model.yMax, .6*model.zMax),ADD); | |
7b2faded | 275 | |
7974acd6 | 276 | colors[p.index] = blendIfColor(colors[p.index], c , ADD); |
e0cfbe20 AG |
277 | |
278 | } | |
279 | ||
7974acd6 MS |
280 | } |
281 | ||
282 | color blendIfColor(color c1, color c2, int mode) { | |
283 | if (c2 != 0) { | |
284 | return blendColor(c1, c2, mode); | |
285 | } | |
286 | return c1; | |
a9aad043 | 287 | } |
e27a8652 | 288 | |
a9aad043 AG |
289 | |
290 | // color c = 0; | |
291 | // 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); | |
292 | // return c; | |
293 | // } | |
a41f334c | 294 | // return lx.hsb(0,0,0); |
a9aad043 AG |
295 | // // else if(spheremode ==2) |
296 | // { color c = 0; | |
a41f334c | 297 | // return lx.hsb(CalcCone( (xyz by = new xyz(0,spherys[2].ybounce.getValuef(),0) ), Px, mid) ); |
a9aad043 AG |
298 | |
299 | // } | |
300 | ||
301 | ||
d8239019 | 302 | // } |
a9aad043 AG |
303 | |
304 | } | |
305 | ||
5bc92bc2 | 306 | class CubeCurl extends SCPattern{ |
b30f14fd AG |
307 | float CH, CW, diag; |
308 | ArrayList<PVector> cubeorigin = new ArrayList<PVector>(); | |
309 | ArrayList<PVector> centerlist = new ArrayList<PVector>(); | |
5bc92bc2 AG |
310 | private SinLFO curl = new SinLFO(0, Cube.EDGE_HEIGHT, 5000 ); |
311 | ||
312 | private SinLFO bg = new SinLFO(180, 220, 3000); | |
313 | ||
314 | CubeCurl(GLucose glucose){ | |
315 | super(glucose); | |
316 | addModulator(curl).trigger(); | |
317 | addModulator(bg).trigger(); | |
7c7625ec AG |
318 | this.CH = Cube.EDGE_HEIGHT; |
319 | this.CW = Cube.EDGE_WIDTH; | |
f1370a0b | 320 | this.diag = sqrt(CW*CW + CW*CW); |
b30f14fd | 321 | |
7c7625ec | 322 | |
b30f14fd | 323 | ArrayList<PVector> centerlistrelative = new ArrayList<PVector>(); |
7c7625ec | 324 | for (int i = 0; i < model.cubes.size(); i++){ |
b30f14fd AG |
325 | Cube a = model.cubes.get(i); |
326 | cubeorigin.add(new PVector(a.x, a.y, a.z)); | |
e0cfbe20 | 327 | centerlist.add(new PVector(a.cx, a.cy, a.cz) ); |
b30f14fd AG |
328 | |
329 | } | |
5bc92bc2 AG |
330 | |
331 | } | |
7c7625ec AG |
332 | //there is definitely a better way of doing this! |
333 | PVector centerofcube(int i) { | |
334 | Cube c = model.cubes.get(i); | |
f1370a0b AG |
335 | |
336 | println(" cube #: " + i + " c.x " + c.x + " c.y " + c.y + " c.z " + c.z ); | |
1d414e45 AG |
337 | // PVector cubeangle = new PVector(c.rx, c.ry, c.rz); |
338 | println("raw x angle: " + c.rx + "raw y angle: " + c.ry + "raw z angle: " + c.rz); | |
f1370a0b AG |
339 | PVector cubecenter = new PVector(c.x + CW/2, c.y + CH/2, c.z + CW/2); |
340 | println("cubecenter unrotated: " + cubecenter.x + " " +cubecenter.y + " " +cubecenter.z ); | |
1d414e45 | 341 | 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 | 342 | // nCos*(y-o.y) - nSin*(z-o.z) + o.y |
1d414e45 | 343 | cubecenter = PVector.add(new PVector(c.x, c.y, c.z), centerrot); |
f1370a0b AG |
344 | println( " cubecenter.x " + cubecenter.x + " cubecenter.y " + cubecenter.y + " cubecenter.z " + cubecenter.z + " "); |
345 | ||
346 | ||
b30f14fd | 347 | return cubecenter; |
7c7625ec AG |
348 | } |
349 | ||
5bc92bc2 AG |
350 | |
351 | void run(double deltaMs){ | |
352 | for (int i =0; i < model.cubes.size(); i++) { | |
353 | Cube c = model.cubes.get(i); | |
354 | float cfloor = c.y; | |
355 | ||
f1370a0b | 356 | // if (i%3 == 0){ |
5bc92bc2 | 357 | |
2bb56822 | 358 | // for (LXPoint p : c.points ){ |
f1370a0b AG |
359 | // // colors[p.index]=color(0,0,0); |
360 | // //float dif = (p.y - c.y); | |
361 | // //colors[p.index] = color( bg.getValuef() , 80 , dif < curl.getValuef() ? 80 : 0, ADD); | |
362 | // } | |
363 | // } | |
5bc92bc2 | 364 | |
f1370a0b | 365 | // else if (i%3 == 1) { |
5bc92bc2 | 366 | |
2bb56822 | 367 | // for (LXPoint p: c.points){ |
f1370a0b AG |
368 | // colors[p.index]=color(0,0,0); |
369 | // float dif = (p.y - c.y); | |
370 | // // colors[p.index] = | |
371 | // // color(bg.getValuef(), | |
372 | // // map(curl.getValuef(), 0, Cube.EDGE_HEIGHT, 20, 100), | |
373 | // // 100 - 10*abs(dif - curl.getValuef()), ADD ); | |
374 | // } | |
375 | // } | |
376 | // else if (i%3 == 2){ | |
b30f14fd | 377 | // centerlist[i].sub(cubeorigin(i); |
2bb56822 | 378 | for (LXPoint p: c.points) { |
b30f14fd | 379 | PVector pv = new PVector(p.x, p.y, p.z); |
f1370a0b | 380 | colors[p.index] =color( constrain(4* pv.dist(centerlist.get(i)), 0, 360) , 50, 100 ); |
b30f14fd | 381 | // colors[p.index] =color(constrain(centerlist[i].x, 0, 360), constrain(centerlist[i].y, 0, 100), ); |
5bc92bc2 AG |
382 | |
383 | ||
b30f14fd | 384 | } |
5bc92bc2 AG |
385 | |
386 | ||
f1370a0b | 387 | //} |
5bc92bc2 AG |
388 | |
389 | } | |
390 | } | |
391 | } | |
392 | ||
a9aad043 AG |
393 | class HueTestHSB extends SCPattern{ |
394 | BasicParameter HueT = new BasicParameter("Hue", .5); | |
395 | BasicParameter SatT = new BasicParameter("Sat", .5); | |
396 | BasicParameter BriT = new BasicParameter("Bright", .5); | |
397 | ||
398 | HueTestHSB(GLucose glucose) { | |
399 | super(glucose); | |
400 | addParameter(HueT); | |
401 | addParameter(SatT); | |
402 | addParameter(BriT); | |
403 | } | |
404 | void run(double deltaMs){ | |
405 | ||
2bb56822 | 406 | for (LXPoint p : model.points) { |
a9aad043 | 407 | color c = 0; |
a41f334c | 408 | c = blendColor(c, lx.hsb(360*HueT.getValuef(), 100*SatT.getValuef(), 100*BriT.getValuef()), ADD); |
a9aad043 AG |
409 | colors[p.index]= c; |
410 | } | |
411 | int now= millis(); | |
412 | if (now % 1000 <= 20) | |
413 | { | |
414 | println("Hue: " + 360*HueT.getValuef() + "Sat: " + 100*SatT.getValuef() + "Bright: " + 100*BriT.getValuef()); | |
415 | } | |
416 | } | |
0b1785e3 | 417 | |
a41f334c | 418 | } |