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