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