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