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