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