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