rotate y finaly working for sinesphere
[SugarCubes.git] / AlexGreen.pde
1 class SineSphere extends DPat {
2 private SawLFO yrot = new SawLFO(0, TWO_PI, 3000);
3 public final Projection sinespin;
4 private BasicParameter rotation = new BasicParameter("rotation", 0);
5 float modelrad = sqrt((model.xMax)*(model.xMax) + (model.yMax)*(model.yMax) + (model.zMax)*(model.zMax));
6 Pick Sshape;
7
8 class Sphery {
9 float f1xcenter, f1ycenter, f1zcenter, f2xcenter , f2ycenter, f2zcenter; //second three are for an ellipse with two foci
10 private SinLFO vibration;
11 private SinLFO surface;
12 private SinLFO vx;
13 private SinLFO xbounce;
14 public SinLFO ybounce;
15 private SinLFO zbounce;
16 float vibration_min, vibration_max, vperiod;
17 public BasicParameter widthparameter;
18 public BasicParameter huespread;
19 public BasicParameter bouncerate;
20 public BasicParameter bounceamp;
21 public PVector circlecenter;
22
23
24
25 public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float vibration_min, float vibration_max, float vperiod)
26 {
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;
33 //addParameter(bounceamp = new BasicParameter("Amp", .5));
34 //addParameter(bouncerate = new BasicParameter("Rate", .5)); //ybounce.modulateDurationBy(bouncerate);
35 addParameter(widthparameter = new BasicParameter("Width", .1));
36 addParameter(huespread = new BasicParameter("Hue", .2));
37
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)
48
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
71 float distfromcirclecenter(float px, float py, float pz, float f1x, float f1y, float f1z)
72 {
73 return dist(px, py, pz, f1x, f1y, f1z);
74 }
75 //void updatespherey(deltaMs, )
76
77 int quadrant(PVector q) {
78 //float theta =
79 if (q.x > f1xcenter ) {return 140;}
80 else {return 250;}
81
82
83
84 }
85 color spheryvalue (PVector p, float f1xcenter, float f1ycenter, float f1zcenter)
86 { circlecenter = new PVector(f1xcenter, f1ycenter, f1zcenter);
87 //switch(sShpape.cur() ) {}
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)
91 - vibration.getValuef() ) ) );
92 }
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() ) {}
96 return lx.hsb(huespread.getValuef()*5*px, dist(model.xMax-px, model.yMax-py, model.zMax-pz, f1xc, f1yc, f1zc) ,
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() ) ) ) ;
101 }
102
103 void run(double deltaMs) {
104 float vv = vibration.getValuef();
105 float ybv = ybounce.getValuef();
106
107 }
108
109 }
110
111
112 final Sphery[] spherys;
113
114 SineSphere(GLucose glucose)
115 {
116 super(glucose);
117 sinespin = new Projection(model);
118 addModulator(yrot).trigger();
119 addParameter(rotation);
120 //Sshape = addPick("Shape", , 1);
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 };
126
127 }
128
129 // public void onParameterChanged(LXParameter parameter)
130 // {
131
132
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 // }
148
149 public void run( double deltaMs) {
150 float t = lx.tempo.rampf();
151 float bpm = lx.tempo.bpmf();
152 spherys[0].run(deltaMs);
153 spherys[1].run(deltaMs);
154 spherys[2].run(deltaMs);
155 sinespin.reset(model)
156
157 // Translate so the center of the car is the origin, offset
158 .translateCenter(model, 0, 0, 0)
159 // .scale(1.3,1.3,1.3)
160 // Rotate around the origin (now the center of the car) about an y-vector
161 .rotate(yrot.getValuef(), 0, 1 , 0)
162 .translate(model.cx, model.cy, model.cz);
163
164
165 //.translateCenter(model, model.cx, , model.cz);
166
167
168 for (Coord p: sinespin)
169 // for (Point p: model.points)
170 {
171 PVector P = new PVector(p.x, p.y, p.z);
172 color c = 0;
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);
176
177 colors[p.index] = lx.hsb(lx.h(c), lx.s(c), lx.b(c));
178
179 }
180
181
182
183 }
184 int spheremode = 0;
185
186 // void keyPressed() {
187 // spheremode++;
188 // }
189
190 // color CalcPoint(PVector Px)
191 // {
192 // // if (spheremode == 0 )
193 //{
194
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 // }
203 // return lx.hsb(0,0,0);
204 // // else if(spheremode ==2)
205 // { color c = 0;
206 // return lx.hsb(CalcCone( (xyz by = new xyz(0,spherys[2].ybounce.getValuef(),0) ), Px, mid) );
207
208 // }
209
210
211 // }
212
213 }
214
215 class CubeCurl extends SCPattern{
216 float CH, CW, diag;
217 ArrayList<PVector> cubeorigin = new ArrayList<PVector>();
218 ArrayList<PVector> centerlist = new ArrayList<PVector>();
219 private SinLFO curl = new SinLFO(0, Cube.EDGE_HEIGHT, 5000 );
220
221 private SinLFO bg = new SinLFO(180, 220, 3000);
222
223 CubeCurl(GLucose glucose){
224 super(glucose);
225 addModulator(curl).trigger();
226 addModulator(bg).trigger();
227 this.CH = Cube.EDGE_HEIGHT;
228 this.CW = Cube.EDGE_WIDTH;
229 this.diag = sqrt(CW*CW + CW*CW);
230
231
232 ArrayList<PVector> centerlistrelative = new ArrayList<PVector>();
233 for (int i = 0; i < model.cubes.size(); i++){
234 Cube a = model.cubes.get(i);
235 cubeorigin.add(new PVector(a.x, a.y, a.z));
236 centerlist.add(centerofcube(i));
237
238 }
239
240 }
241 //there is definitely a better way of doing this!
242 PVector centerofcube(int i) {
243 Cube c = model.cubes.get(i);
244
245 println(" cube #: " + i + " c.x " + c.x + " c.y " + c.y + " c.z " + c.z );
246 // PVector cubeangle = new PVector(c.rx, c.ry, c.rz);
247 println("raw x angle: " + c.rx + "raw y angle: " + c.ry + "raw z angle: " + c.rz);
248 PVector cubecenter = new PVector(c.x + CW/2, c.y + CH/2, c.z + CW/2);
249 println("cubecenter unrotated: " + cubecenter.x + " " +cubecenter.y + " " +cubecenter.z );
250 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);
251 // nCos*(y-o.y) - nSin*(z-o.z) + o.y
252 cubecenter = PVector.add(new PVector(c.x, c.y, c.z), centerrot);
253 println( " cubecenter.x " + cubecenter.x + " cubecenter.y " + cubecenter.y + " cubecenter.z " + cubecenter.z + " ");
254
255
256 return cubecenter;
257 }
258
259
260 void run(double deltaMs){
261 for (int i =0; i < model.cubes.size(); i++) {
262 Cube c = model.cubes.get(i);
263 float cfloor = c.y;
264
265 // if (i%3 == 0){
266
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 // }
273
274 // else if (i%3 == 1) {
275
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){
286 // centerlist[i].sub(cubeorigin(i);
287 for (Point p: c.points) {
288 PVector pv = new PVector(p.x, p.y, p.z);
289 colors[p.index] =color( constrain(4* pv.dist(centerlist.get(i)), 0, 360) , 50, 100 );
290 // colors[p.index] =color(constrain(centerlist[i].x, 0, 360), constrain(centerlist[i].y, 0, 100), );
291
292
293 }
294
295
296 //}
297
298 }
299 }
300 }
301
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
307 HueTestHSB(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;
317 c = blendColor(c, lx.hsb(360*HueT.getValuef(), 100*SatT.getValuef(), 100*BriT.getValuef()), ADD);
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 }
326
327 }