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