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