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