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