more cubes, maxed out, sinesphere multiple projections
[SugarCubes.git] / AlexGreen.pde
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 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
10 class Sphery {
11 float f1xcenter, f1ycenter, f1zcenter, f2xcenter , f2ycenter, f2zcenter; //second three are for an ellipse with two foci
12 private SinLFO vibration;
13 private SinLFO surface;
14 private SinLFO vx;
15 private SinLFO xbounce;
16 public SinLFO ybounce;
17 private SinLFO zbounce;
18 float vibration_min, vibration_max, vperiod;
19 public BasicParameter widthparameter;
20 public BasicParameter huespread;
21 public BasicParameter bouncerate;
22 public BasicParameter bounceamp;
23 public PVector circlecenter;
24
25
26
27 public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float vibration_min, float vibration_max, float vperiod)
28 {
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;
35 //addParameter(bounceamp = new BasicParameter("Amp", .5));
36 //addParameter(bouncerate = new BasicParameter("Rate", .5)); //ybounce.modulateDurationBy(bouncerate);
37 addParameter(widthparameter = new BasicParameter("Width", .1));
38 addParameter(huespread = new BasicParameter("Hue", .2));
39
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)
50
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
73 float distfromcirclecenter(float px, float py, float pz, float f1x, float f1y, float f1z)
74 {
75 return dist(px, py, pz, f1x, f1y, f1z);
76 }
77 //void updatespherey(deltaMs, )
78
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 ()
85
86
87
88 }
89 color spheryvalue (PVector p, float f1xcenter, float f1ycenter, float f1zcenter)
90 { circlecenter = new PVector(f1xcenter, f1ycenter, f1zcenter);
91 //switch(sShpape.cur() ) {}
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)
95 - vibration.getValuef() ) ) );
96 }
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() ) {}
100 return lx.hsb(huespread.getValuef()*5*px, dist(model.xMax-px, model.yMax-py, model.zMax-pz, f1xc, f1yc, f1zc) ,
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() ) ) ) ;
105 }
106
107 void run(double deltaMs) {
108 float vv = vibration.getValuef();
109 float ybv = ybounce.getValuef();
110
111 }
112
113 }
114
115
116 final Sphery[] spherys;
117
118 SineSphere(GLucose glucose)
119 {
120 super(glucose);
121 sinespin = new Projection(model);
122 sinespin2 = new Projection(model);
123 addModulator(yrot).trigger();
124 addModulator(yrot2).trigger();
125 addParameter(rotation);
126 //Sshape = addPick("Shape", , 1);
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),
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
136 };
137
138 }
139
140 // public void onParameterChanged(LXParameter parameter)
141 // {
142
143
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 // }
159
160 public void run( double deltaMs) {
161 float t = lx.tempo.rampf();
162 float bpm = lx.tempo.bpmf();
163 spherys[0].run(deltaMs);
164 spherys[1].run(deltaMs);
165 spherys[2].run(deltaMs);
166 spherys[3].run(deltaMs);
167
168 sinespin.reset(model)
169
170
171 // Translate so the center of the car is the origin, offset
172 .translateCenter(model, 0, 0, 0)
173 // .scale(1.3,1.3,1.3)
174 // Rotate around the origin (now the center of the car) about an y-vector
175 .rotate(yrot.getValuef(), 0, 1 , 0)
176 .translate(model.cx, model.cy, model.cz);
177
178
179
180
181
182 for (Coord p: sinespin)
183 // for (Point p: model.points)
184 {
185 PVector P = new PVector(p.x, p.y, p.z);
186 color c = 0;
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);
190
191
192 colors[p.index] = lx.hsb(lx.h(c), lx.s(c), lx.b(c));
193
194
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
209
210
211 }
212
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 // }
218 // return lx.hsb(0,0,0);
219 // // else if(spheremode ==2)
220 // { color c = 0;
221 // return lx.hsb(CalcCone( (xyz by = new xyz(0,spherys[2].ybounce.getValuef(),0) ), Px, mid) );
222
223 // }
224
225
226 // }
227
228 }
229
230 class CubeCurl extends SCPattern{
231 float CH, CW, diag;
232 ArrayList<PVector> cubeorigin = new ArrayList<PVector>();
233 ArrayList<PVector> centerlist = new ArrayList<PVector>();
234 private SinLFO curl = new SinLFO(0, Cube.EDGE_HEIGHT, 5000 );
235
236 private SinLFO bg = new SinLFO(180, 220, 3000);
237
238 CubeCurl(GLucose glucose){
239 super(glucose);
240 addModulator(curl).trigger();
241 addModulator(bg).trigger();
242 this.CH = Cube.EDGE_HEIGHT;
243 this.CW = Cube.EDGE_WIDTH;
244 this.diag = sqrt(CW*CW + CW*CW);
245
246
247 ArrayList<PVector> centerlistrelative = new ArrayList<PVector>();
248 for (int i = 0; i < model.cubes.size(); i++){
249 Cube a = model.cubes.get(i);
250 cubeorigin.add(new PVector(a.x, a.y, a.z));
251 centerlist.add(new PVector(a.cx, a.cy, a.cz) );
252
253 }
254
255 }
256 //there is definitely a better way of doing this!
257 PVector centerofcube(int i) {
258 Cube c = model.cubes.get(i);
259
260 println(" cube #: " + i + " c.x " + c.x + " c.y " + c.y + " c.z " + c.z );
261 // PVector cubeangle = new PVector(c.rx, c.ry, c.rz);
262 println("raw x angle: " + c.rx + "raw y angle: " + c.ry + "raw z angle: " + c.rz);
263 PVector cubecenter = new PVector(c.x + CW/2, c.y + CH/2, c.z + CW/2);
264 println("cubecenter unrotated: " + cubecenter.x + " " +cubecenter.y + " " +cubecenter.z );
265 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);
266 // nCos*(y-o.y) - nSin*(z-o.z) + o.y
267 cubecenter = PVector.add(new PVector(c.x, c.y, c.z), centerrot);
268 println( " cubecenter.x " + cubecenter.x + " cubecenter.y " + cubecenter.y + " cubecenter.z " + cubecenter.z + " ");
269
270
271 return cubecenter;
272 }
273
274
275 void run(double deltaMs){
276 for (int i =0; i < model.cubes.size(); i++) {
277 Cube c = model.cubes.get(i);
278 float cfloor = c.y;
279
280 // if (i%3 == 0){
281
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 // }
288
289 // else if (i%3 == 1) {
290
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){
301 // centerlist[i].sub(cubeorigin(i);
302 for (Point p: c.points) {
303 PVector pv = new PVector(p.x, p.y, p.z);
304 colors[p.index] =color( constrain(4* pv.dist(centerlist.get(i)), 0, 360) , 50, 100 );
305 // colors[p.index] =color(constrain(centerlist[i].x, 0, 360), constrain(centerlist[i].y, 0, 100), );
306
307
308 }
309
310
311 //}
312
313 }
314 }
315 }
316
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
322 HueTestHSB(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;
332 c = blendColor(c, lx.hsb(360*HueT.getValuef(), 100*SatT.getValuef(), 100*BriT.getValuef()), ADD);
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 }
341
342 }