1 class SineSphere extends SCPattern {
2 private SawLFO yrot = new SawLFO(0, TWO_PI, 3000);
3 private SawLFO yrot2 = new SawLFO(0, -TWO_PI, 8000);
4 public BasicParameter huespread = new BasicParameter("Hue", 0, 180);
5 public BasicParameter widthparameter= new BasicParameter("Width", .2);
7 private int channel = 0;
8 private int velocity = 0;
9 public final LXProjection sinespin;
10 float modelrad = sqrt((model.xMax)*(model.xMax) + (model.yMax)*(model.yMax) + (model.zMax)*(model.zMax));
12 public final PVector P = new PVector();
15 float f1xcenter, f1ycenter, f1zcenter, f2xcenter , f2ycenter, f2zcenter; //second three are for an ellipse with two foci
16 private SinLFO vibration;
17 private SinLFO surface;
19 private SinLFO xbounce;
20 public SinLFO ybounce;
21 private SinLFO zbounce;
22 float vibration_min, vibration_max, vperiod;
24 //public BasicParameter huespread;
25 public BasicParameter bouncerate;
26 public BasicParameter bounceamp;
27 public BasicParameter vibrationrate;
28 public final PVector circlecenter = new PVector();
30 public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float vibration_min, float vibration_max, float vperiod)
32 this.f1xcenter = f1xcenter;
33 this.f1ycenter = f1ycenter;
34 this.f1zcenter = f1zcenter;
35 this.vibration_min = vibration_min;
36 this.vibration_max = vibration_max;
37 this.vperiod = vperiod;
38 //addParameter(bounceamp = new BasicParameter("Amp", .5));
39 //addParameter(bouncerate = new BasicParameter("Rate", .5)); //ybounce.modulateDurationBy(bouncerate);
40 //addParameter(vibrationrate = new BasicParameter("vibration", 1000, 10000));
41 //addParameter(widthparameter = new BasicParameter("Width", .2));
44 addModulator( vx = new SinLFO(500, 10000, 100000)).trigger() ;
45 //addModulator(xbounce = new SinLFO(model.xMax/3, 2*model.yMax/3, 2000)).trigger();
46 addModulator(ybounce= new SinLFO(model.yMax/3, 2*model.yMax/3, 240000./lx.tempo.bpm())).trigger(); //bounce.modulateDurationBy
48 //addModulator(bounceamp); //ybounce.setMagnitude(bouncerate);
49 addModulator( vibration = new SinLFO(vibration_min , vibration_max, 10000)).trigger(); //vibration.setPeriod(240000/lx.tempo.bpm());
54 // public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float f2xcenter, float f2ycenter, float f2zcenter,
55 // float vibration_min, float vibration_max, float vperiod)
58 // this.f1xcenter = f1xcenter;
59 // this.f1ycenter = f1ycenter;
60 // this.f1zcenter = f1zcenter;
61 // this.f2xcenter = f2xcenter;
62 // this.f2ycenter = f2ycenter;
63 // this.f2zcenter = f2zcenter;
64 // this.vibration_min = vibration_min;
65 // this.vibration_max = vibration_max;
66 // this.vperiod = vperiod;
67 // //addModulator(xbounce = new SinLFO(model.xMax/3, 2*model.yMax/3, 2000)).trigger();
68 // addModulator(ybounce).trigger();
69 // addModulator( vibration = new SinLFO(vibration_min , vibration_max, lx.tempo.rampf())).trigger(); //vibration.modulateDurationBy(vx);
70 // addParameter(widthparameter = new BasicParameter("Width", .1));
71 // //addParameter(huespread = new BasicParameter("bonk", .2));
77 void setVibrationPeriod(double period){
78 // to-do: make this conditional upon time signature
80 vibration.setPeriod(period);
85 float distfromcirclecenter(float px, float py, float pz, float f1x, float f1y, float f1z)
87 return dist(px, py, pz, f1x, f1y, f1z);
89 //void updatespherey(deltaMs, )
91 float quadrant(PVector q) {
92 float qtheta = atan2( (q.x-f1xcenter) , (q.z - f1zcenter) );
95 return map(qtheta, -PI/2, PI/2, 160-huespread.getValuef(), 240 +huespread.getValuef());
96 //if (q.x > f1xcenter ) {return 140 ;}
99 color spheryvalue (PVector p, float f1xcenter, float f1ycenter, float f1zcenter) {
100 circlecenter.set(f1xcenter, f1ycenter, f1zcenter);
103 //switch(sShpape.cur() ) {}
105 float b = max(0, 100 - 100*widthparameter.getValuef()*abs(p.dist(circlecenter)
106 - vibration.getValuef() ) );
113 constrain(quadrant(p), 0, 360),
118 color ellipsevalue(float px, float py, float pz , float f1xc, float f1yc, float f1zc, float f2xc, float f2yc, float f2zc)
120 //switch(sShpape.cur() ) {}
121 return lx.hsb(huespread.getValuef()*5*px, dist(model.xMax-px, model.yMax-py, model.zMax-pz, f1xc, f1yc, f1zc) ,
122 max(0, 100 - 100*widthparameter.getValuef() *
123 abs( (dist(px, py, pz, f1xc, ybounce.getValuef(), f1zc) +
124 (dist(px, py , pz, f2xc, ybounce.getValuef(), f2zc) ) )/2
125 - 1.2*vibration.getValuef() ) ) ) ;
128 void run(double deltaMs) {
129 float vv = vibration.getValuef();
130 float ybv = ybounce.getValuef();
136 // public boolean gridPressed(int row, int co){
137 // midiengine.grid.setState();
143 public boolean noteOn(Note note) {
144 pitch= note.getPitch();
145 velocity=note.getVelocity();
146 channel=note.getChannel();
150 final Sphery[] spherys;
152 SineSphere(GLucose glucose)
155 sinespin = new LXProjection(model);
156 sinespin2 = new Projection(model);
157 addParameter(huespread);
158 addParameter(rotationx);
159 addParameter(rotationy);
160 addParameter(rotationz);
161 addModulator(yrot).trigger();
162 addModulator(yrot2).trigger();
164 //addParameter(huespread);
165 //Sshape = addPick("Shape", , 1);
166 spherys = new Sphery[] {
167 new Sphery(model.xMax/4, model.yMax/2, model.zMax/2, modelrad/16, modelrad/8, 3000),
168 new Sphery(.75*model.xMax, model.yMax/2, model.zMax/2, modelrad/20, modelrad/10, 2000),
169 new Sphery(model.xMax/2, model.yMax/2, model.zMax/2, modelrad/4, modelrad/8, 2300),
171 new Sphery(.3*model.xMax, .4*model.yMax, .6*model.zMax, modelrad/16, modelrad/8, 4000),
172 new Sphery(.75*model.xMax, model.yMax/2, model.zMax/2, modelrad/20, modelrad/10, 2000),
173 new Sphery(model.xMax/2, model.yMax/2, model.zMax/2, modelrad/4, modelrad/8, 2300),
178 // public void onParameterChanged(LXParameter parameter)
182 // for (Sphery s : spherys) {
183 // if (s == null) continue;
184 // double bampv = s.bounceamp.getValue();
185 // double brv = s.bouncerate.getValue();
186 // double tempobounce = lx.tempo.bpm();
187 // if (parameter == s.bounceamp)
189 // s.ybounce.setRange(bampv*model.yMax/3 , bampv*2*model.yMax/3, brv);
191 // else if ( parameter == s.bouncerate )
193 // s.ybounce.setDuration(120000./tempobounce);
198 public void run( double deltaMs) {
199 double t = lx.tempo.ramp();
200 double bpm = lx.tempo.bpm();
201 //spherys[0].run(deltaMs);
202 //spherys[1].run(deltaMs);
203 //spherys[2].run(deltaMs);
204 //spherys[3].run(deltaMs);]
207 .rotate(yrot.getValuef(), 0, 1, 0);
211 case 53: t = .5*t; bpm = .5*bpm; break;
213 case 54: t = t; bpm = bpm; break;
215 case 55: t = 2*t; bpm = 2*bpm; break;
217 default: t= t; bpm = bpm;
222 for ( Sphery s: spherys){
223 s.setVibrationPeriod(480000/bpm);
224 s.vibration.setBasis(t);
226 sinespin.reset(model)
229 // Translate so the center of the car is the origin, offset
230 .translateCenter(model, 0, 0, 0)
231 // .scale(1.3,1.3,1.3)
232 // Rotate around the origin (now the center of the car) about an y-vector
233 .rotate(yrot.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef())
234 .translate(model.cx, model.cy, model.cz);
240 for (Coord p: sinespin)
241 // for (Point p: model.points)
243 P.set(p.x, p.y, p.z);
244 // PVector P = new PVector(p.x, p.y, p.z);
246 c = blendIfColor(c, spherys[1].spheryvalue(P, .75*model.xMax, model.yMax/2, model.zMax/2), ADD);
247 c = blendIfColor(c, spherys[0].spheryvalue(P, model.xMax/4, model.yMax/4, model.zMax/2), ADD);
248 c = blendIfColor(c, spherys[2].spheryvalue(P, model.xMax/2, model.yMax/2, model.zMax/2),ADD);
255 sinespin2.reset(model).
256 translateCenter(model,0,0,0).
257 rotate(yrot2.getValuef(), 0, 1, 0).
258 translate(model.cx,model.cy,model.cz);
260 for (Coord p: sinespin2)
262 // PVector P = new PVector(p.x, p.y, p.z);
263 P.set(p.x, p.y, p.z);
264 c = blendIfColor(c, spherys[3].spheryvalue(P, .3*model.xMax, .7*model.yMax, .6*model.zMax),ADD);
266 colors[p.index] = blendIfColor(colors[p.index], c , ADD);
272 color blendIfColor(color c1, color c2, int mode) {
274 return blendColor(c1, c2, mode);
281 // 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);
284 // return lx.hsb(0,0,0);
285 // // else if(spheremode ==2)
287 // return lx.hsb(CalcCone( (xyz by = new xyz(0,spherys[2].ybounce.getValuef(),0) ), Px, mid) );
296 class CubeCurl extends SCPattern{
298 ArrayList<PVector> cubeorigin = new ArrayList<PVector>();
299 ArrayList<PVector> centerlist = new ArrayList<PVector>();
300 private SinLFO curl = new SinLFO(0, Cube.EDGE_HEIGHT, 5000 );
302 private SinLFO bg = new SinLFO(180, 220, 3000);
304 CubeCurl(GLucose glucose){
306 addModulator(curl).trigger();
307 addModulator(bg).trigger();
308 this.CH = Cube.EDGE_HEIGHT;
309 this.CW = Cube.EDGE_WIDTH;
310 this.diag = sqrt(CW*CW + CW*CW);
313 ArrayList<PVector> centerlistrelative = new ArrayList<PVector>();
314 for (int i = 0; i < model.cubes.size(); i++){
315 Cube a = model.cubes.get(i);
316 cubeorigin.add(new PVector(a.x, a.y, a.z));
317 centerlist.add(new PVector(a.cx, a.cy, a.cz) );
322 //there is definitely a better way of doing this!
323 PVector centerofcube(int i) {
324 Cube c = model.cubes.get(i);
326 println(" cube #: " + i + " c.x " + c.x + " c.y " + c.y + " c.z " + c.z );
327 // PVector cubeangle = new PVector(c.rx, c.ry, c.rz);
328 println("raw x angle: " + c.rx + "raw y angle: " + c.ry + "raw z angle: " + c.rz);
329 PVector cubecenter = new PVector(c.x + CW/2, c.y + CH/2, c.z + CW/2);
330 println("cubecenter unrotated: " + cubecenter.x + " " +cubecenter.y + " " +cubecenter.z );
331 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);
332 // nCos*(y-o.y) - nSin*(z-o.z) + o.y
333 cubecenter = PVector.add(new PVector(c.x, c.y, c.z), centerrot);
334 println( " cubecenter.x " + cubecenter.x + " cubecenter.y " + cubecenter.y + " cubecenter.z " + cubecenter.z + " ");
341 void run(double deltaMs){
342 for (int i =0; i < model.cubes.size(); i++) {
343 Cube c = model.cubes.get(i);
348 // for (LXPoint p : c.points ){
349 // // colors[p.index]=color(0,0,0);
350 // //float dif = (p.y - c.y);
351 // //colors[p.index] = color( bg.getValuef() , 80 , dif < curl.getValuef() ? 80 : 0, ADD);
355 // else if (i%3 == 1) {
357 // for (LXPoint p: c.points){
358 // colors[p.index]=color(0,0,0);
359 // float dif = (p.y - c.y);
360 // // colors[p.index] =
361 // // color(bg.getValuef(),
362 // // map(curl.getValuef(), 0, Cube.EDGE_HEIGHT, 20, 100),
363 // // 100 - 10*abs(dif - curl.getValuef()), ADD );
366 // else if (i%3 == 2){
367 // centerlist[i].sub(cubeorigin(i);
368 for (LXPoint p: c.points) {
369 PVector pv = new PVector(p.x, p.y, p.z);
370 colors[p.index] =color( constrain(4* pv.dist(centerlist.get(i)), 0, 360) , 50, 100 );
371 // colors[p.index] =color(constrain(centerlist[i].x, 0, 360), constrain(centerlist[i].y, 0, 100), );
383 class HueTestHSB extends SCPattern{
384 BasicParameter HueT = new BasicParameter("Hue", .5);
385 BasicParameter SatT = new BasicParameter("Sat", .5);
386 BasicParameter BriT = new BasicParameter("Bright", .5);
388 HueTestHSB(GLucose glucose) {
394 void run(double deltaMs){
396 for (LXPoint p : model.points) {
398 c = blendColor(c, lx.hsb(360*HueT.getValuef(), 100*SatT.getValuef(), 100*BriT.getValuef()), ADD);
402 if (now % 1000 <= 20)
404 println("Hue: " + 360*HueT.getValuef() + "Sat: " + 100*SatT.getValuef() + "Bright: " + 100*BriT.getValuef());