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);
5 public final Projection sinespin;
6 public final Projection sinespin2;
8 //to-do: how to sync all hues across sphery's via one basicparameter
9 //public BasicParameter huespread = new BasicParameter("HueSpread", 180, 360);
10 public BasicParameter rotationx = new BasicParameter("rotx", 0, 0, 1 );
11 public BasicParameter rotationy = new BasicParameter("roty", 1, 0, 1);
12 public BasicParameter rotationz = new BasicParameter("rotz", 0, 0, 1);
14 float modelrad = sqrt((model.xMax)*(model.xMax) + (model.yMax)*(model.yMax) + (model.zMax)*(model.zMax));
16 public final PVector P = new PVector();
19 float f1xcenter, f1ycenter, f1zcenter, f2xcenter , f2ycenter, f2zcenter; //second three are for an ellipse with two foci
20 private SinLFO vibration;
21 private SinLFO surface;
23 private SinLFO xbounce;
24 public SinLFO ybounce;
25 private SinLFO zbounce;
26 float vibration_min, vibration_max, vperiod;
27 public BasicParameter widthparameter;
28 public BasicParameter huespread;
29 public BasicParameter bouncerate;
30 public BasicParameter bounceamp;
31 public BasicParameter vibrationrate;
32 public final PVector circlecenter = new PVector();
34 public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float vibration_min, float vibration_max, float vperiod)
36 this.f1xcenter = f1xcenter;
37 this.f1ycenter = f1ycenter;
38 this.f1zcenter = f1zcenter;
39 this.vibration_min = vibration_min;
40 this.vibration_max = vibration_max;
41 this.vperiod = vperiod;
42 //addParameter(bounceamp = new BasicParameter("Amp", .5));
43 //addParameter(bouncerate = new BasicParameter("Rate", .5)); //ybounce.modulateDurationBy(bouncerate);
44 //addParameter(vibrationrate = new BasicParameter("vibration", 1000, 10000));
45 addParameter(widthparameter = new BasicParameter("Width", .2));
46 addParameter(huespread = new BasicParameter("Hue", 0, 180));
48 addModulator( vx = new SinLFO(500, 10000, 100000)).trigger() ;
49 //addModulator(xbounce = new SinLFO(model.xMax/3, 2*model.yMax/3, 2000)).trigger();
50 addModulator(ybounce= new SinLFO(model.yMax/3, 2*model.yMax/3, 240000./lx.tempo.bpm())).trigger(); //bounce.modulateDurationBy
52 //addModulator(bounceamp); //ybounce.setMagnitude(bouncerate);
53 addModulator( vibration = new SinLFO(vibration_min , vibration_max, 240000)).trigger(); //vibration.setPeriod(240000/lx.tempo.bpm());
58 public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float f2xcenter, float f2ycenter, float f2zcenter,
59 float vibration_min, float vibration_max, float vperiod)
62 this.f1xcenter = f1xcenter;
63 this.f1ycenter = f1ycenter;
64 this.f1zcenter = f1zcenter;
65 this.f2xcenter = f2xcenter;
66 this.f2ycenter = f2ycenter;
67 this.f2zcenter = f2zcenter;
68 this.vibration_min = vibration_min;
69 this.vibration_max = vibration_max;
70 this.vperiod = vperiod;
71 //addModulator(xbounce = new SinLFO(model.xMax/3, 2*model.yMax/3, 2000)).trigger();
72 addModulator(ybounce).trigger();
73 addModulator( vibration = new SinLFO(vibration_min , vibration_max, lx.tempo.rampf())).trigger(); //vibration.modulateDurationBy(vx);
74 addParameter(widthparameter = new BasicParameter("Width", .1));
75 addParameter(huespread = new BasicParameter("Hue", .2));
80 void setVibrationPeriod(double period){
81 // to-do: make this conditional upon time signature
83 vibration.setPeriod(period);
88 float distfromcirclecenter(float px, float py, float pz, float f1x, float f1y, float f1z)
90 return dist(px, py, pz, f1x, f1y, f1z);
92 //void updatespherey(deltaMs, )
94 float quadrant(PVector q) {
95 float qtheta = atan2( (q.x-f1xcenter) , (q.z - f1zcenter) );
98 return map(qtheta, -PI/2, PI/2, 160-huespread.getValuef(), 240 +huespread.getValuef());
99 //if (q.x > f1xcenter ) {return 140 ;}
102 color spheryvalue (PVector p, float f1xcenter, float f1ycenter, float f1zcenter) {
103 circlecenter.set(f1xcenter, f1ycenter, f1zcenter);
106 //switch(sShpape.cur() ) {}
108 float b = max(0, 100 - 100*widthparameter.getValuef()*abs(p.dist(circlecenter)
109 - vibration.getValuef() ) );
116 constrain(quadrant(p), 0, 360),
121 color ellipsevalue(float px, float py, float pz , float f1xc, float f1yc, float f1zc, float f2xc, float f2yc, float f2zc)
123 //switch(sShpape.cur() ) {}
124 return lx.hsb(huespread.getValuef()*5*px, dist(model.xMax-px, model.yMax-py, model.zMax-pz, f1xc, f1yc, f1zc) ,
125 max(0, 100 - 100*widthparameter.getValuef() *
126 abs( (dist(px, py, pz, f1xc, ybounce.getValuef(), f1zc) +
127 (dist(px, py , pz, f2xc, ybounce.getValuef(), f2zc) ) )/2
128 - 1.2*vibration.getValuef() ) ) ) ;
131 void run(double deltaMs) {
132 float vv = vibration.getValuef();
133 float ybv = ybounce.getValuef();
140 final Sphery[] spherys;
142 SineSphere(GLucose glucose)
145 sinespin = new Projection(model);
146 sinespin2 = new Projection(model);
147 addParameter(rotationx);
148 addParameter(rotationy);
149 addParameter(rotationz);
150 addModulator(yrot).trigger();
151 addModulator(yrot2).trigger();
153 //addParameter(huespread);
154 //Sshape = addPick("Shape", , 1);
155 spherys = new Sphery[] {
156 new Sphery(model.xMax/4, model.yMax/2, model.zMax/2, modelrad/16, modelrad/8, 3000),
157 new Sphery(.75*model.xMax, model.yMax/2, model.zMax/2, modelrad/20, modelrad/10, 2000),
158 new Sphery(model.xMax/2, model.yMax/2, model.zMax/2, modelrad/4, modelrad/8, 2300),
160 new Sphery(.3*model.xMax, .4*model.yMax, .6*model.zMax, modelrad/16, modelrad/8, 4000),
161 new Sphery(.75*model.xMax, model.yMax/2, model.zMax/2, modelrad/20, modelrad/10, 2000),
162 new Sphery(model.xMax/2, model.yMax/2, model.zMax/2, modelrad/4, modelrad/8, 2300),
167 // public void onParameterChanged(LXParameter parameter)
171 // for (Sphery s : spherys) {
172 // if (s == null) continue;
173 // double bampv = s.bounceamp.getValue();
174 // double brv = s.bouncerate.getValue();
175 // double tempobounce = lx.tempo.bpm();
176 // if (parameter == s.bounceamp)
178 // s.ybounce.setRange(bampv*model.yMax/3 , bampv*2*model.yMax/3, brv);
180 // else if ( parameter == s.bouncerate )
182 // s.ybounce.setDuration(120000./tempobounce);
187 public void run( double deltaMs) {
188 double t = lx.tempo.ramp();
189 double bpm = lx.tempo.bpm();
190 spherys[0].run(deltaMs);
191 spherys[1].run(deltaMs);
192 spherys[2].run(deltaMs);
193 spherys[3].run(deltaMs);
194 for ( Sphery s: spherys){
195 s.setVibrationPeriod(240000/bpm);
196 s.vibration.setBasis(t);
198 sinespin.reset(model)
201 // Translate so the center of the car is the origin, offset
202 .translateCenter(model, 0, 0, 0)
203 // .scale(1.3,1.3,1.3)
204 // Rotate around the origin (now the center of the car) about an y-vector
205 .rotate(yrot.getValuef(), rotationx.getValuef(), rotationy.getValuef() , rotationz.getValuef())
206 .translate(model.cx, model.cy, model.cz);
212 for (Coord p: sinespin)
213 // for (Point p: model.points)
215 P.set(p.x, p.y, p.z);
216 // PVector P = new PVector(p.x, p.y, p.z);
218 c = blendIfColor(c, spherys[1].spheryvalue(P, .75*model.xMax, model.yMax/2, model.zMax/2), ADD);
219 c = blendIfColor(c, spherys[0].spheryvalue(P, model.xMax/4, model.yMax/4, model.zMax/2), ADD);
220 c = blendIfColor(c, spherys[2].spheryvalue(P, model.xMax/2, model.yMax/2, model.zMax/2),ADD);
227 sinespin2.reset(model).
228 translateCenter(model,0,0,0).
229 rotate(yrot2.getValuef(), 0, 1, 0).
230 translate(model.cx,model.cy,model.cz);
232 for (Coord p: sinespin2)
234 // PVector P = new PVector(p.x, p.y, p.z);
235 P.set(p.x, p.y, p.z);
236 c = blendIfColor(c, spherys[3].spheryvalue(P, .3*model.xMax, .7*model.yMax, .6*model.zMax),ADD);
238 colors[p.index] = blendIfColor(colors[p.index], c , ADD);
246 color blendIfColor(color c1, color c2, int mode) {
248 return blendColor(c1, c2, mode);
255 // 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);
258 // return lx.hsb(0,0,0);
259 // // else if(spheremode ==2)
261 // return lx.hsb(CalcCone( (xyz by = new xyz(0,spherys[2].ybounce.getValuef(),0) ), Px, mid) );
270 class CubeCurl extends SCPattern{
272 ArrayList<PVector> cubeorigin = new ArrayList<PVector>();
273 ArrayList<PVector> centerlist = new ArrayList<PVector>();
274 private SinLFO curl = new SinLFO(0, Cube.EDGE_HEIGHT, 5000 );
276 private SinLFO bg = new SinLFO(180, 220, 3000);
278 CubeCurl(GLucose glucose){
280 addModulator(curl).trigger();
281 addModulator(bg).trigger();
282 this.CH = Cube.EDGE_HEIGHT;
283 this.CW = Cube.EDGE_WIDTH;
284 this.diag = sqrt(CW*CW + CW*CW);
287 ArrayList<PVector> centerlistrelative = new ArrayList<PVector>();
288 for (int i = 0; i < model.cubes.size(); i++){
289 Cube a = model.cubes.get(i);
290 cubeorigin.add(new PVector(a.x, a.y, a.z));
291 centerlist.add(new PVector(a.cx, a.cy, a.cz) );
296 //there is definitely a better way of doing this!
297 PVector centerofcube(int i) {
298 Cube c = model.cubes.get(i);
300 println(" cube #: " + i + " c.x " + c.x + " c.y " + c.y + " c.z " + c.z );
301 // PVector cubeangle = new PVector(c.rx, c.ry, c.rz);
302 println("raw x angle: " + c.rx + "raw y angle: " + c.ry + "raw z angle: " + c.rz);
303 PVector cubecenter = new PVector(c.x + CW/2, c.y + CH/2, c.z + CW/2);
304 println("cubecenter unrotated: " + cubecenter.x + " " +cubecenter.y + " " +cubecenter.z );
305 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);
306 // nCos*(y-o.y) - nSin*(z-o.z) + o.y
307 cubecenter = PVector.add(new PVector(c.x, c.y, c.z), centerrot);
308 println( " cubecenter.x " + cubecenter.x + " cubecenter.y " + cubecenter.y + " cubecenter.z " + cubecenter.z + " ");
315 void run(double deltaMs){
316 for (int i =0; i < model.cubes.size(); i++) {
317 Cube c = model.cubes.get(i);
322 // for (Point p : c.points ){
323 // // colors[p.index]=color(0,0,0);
324 // //float dif = (p.y - c.y);
325 // //colors[p.index] = color( bg.getValuef() , 80 , dif < curl.getValuef() ? 80 : 0, ADD);
329 // else if (i%3 == 1) {
331 // for (Point p: c.points){
332 // colors[p.index]=color(0,0,0);
333 // float dif = (p.y - c.y);
334 // // colors[p.index] =
335 // // color(bg.getValuef(),
336 // // map(curl.getValuef(), 0, Cube.EDGE_HEIGHT, 20, 100),
337 // // 100 - 10*abs(dif - curl.getValuef()), ADD );
340 // else if (i%3 == 2){
341 // centerlist[i].sub(cubeorigin(i);
342 for (Point p: c.points) {
343 PVector pv = new PVector(p.x, p.y, p.z);
344 colors[p.index] =color( constrain(4* pv.dist(centerlist.get(i)), 0, 360) , 50, 100 );
345 // colors[p.index] =color(constrain(centerlist[i].x, 0, 360), constrain(centerlist[i].y, 0, 100), );
357 class HueTestHSB extends SCPattern{
358 BasicParameter HueT = new BasicParameter("Hue", .5);
359 BasicParameter SatT = new BasicParameter("Sat", .5);
360 BasicParameter BriT = new BasicParameter("Bright", .5);
362 HueTestHSB(GLucose glucose) {
368 void run(double deltaMs){
370 for (Point p : model.points) {
372 c = blendColor(c, lx.hsb(360*HueT.getValuef(), 100*SatT.getValuef(), 100*BriT.getValuef()), ADD);
376 if (now % 1000 <= 20)
378 println("Hue: " + 360*HueT.getValuef() + "Sat: " + 100*SatT.getValuef() + "Bright: " + 100*BriT.getValuef());