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