Merge branch 'master' of https://github.com/sugarcubes/SugarCubes
[SugarCubes.git] / AlexGreen.pde
CommitLineData
d8239019
AG
1class SineSphere extends SCPattern {
2 private SinLFO yrot = new SinLFO(0, TWO_PI, 2000);
3 public final Projection sinespin;
a9aad043 4 float modelrad = sqrt((model.xMax)*(model.xMax) + (model.yMax)*(model.yMax) + (model.zMax)*(model.zMax));
a9aad043
AG
5 Pick Sshape;
6
0b1785e3 7 class Sphery {
a9aad043 8 float f1xcenter, f1ycenter, f1zcenter, f2xcenter , f2ycenter, f2zcenter; //second three are for an ellipse with two foci
0b1785e3
AG
9 private SinLFO vibration;
10 private SinLFO surface;
11 private SinLFO vx;
a9aad043
AG
12 private SinLFO xbounce;
13 public SinLFO ybounce;
14 private SinLFO zbounce;
0b1785e3 15 float vibration_min, vibration_max, vperiod;
a9aad043
AG
16 public BasicParameter widthparameter;
17 public BasicParameter huespread;
18 public BasicParameter bouncerate;
19 public BasicParameter bounceamp;
0b1785e3 20
a316cb97 21
a9aad043
AG
22
23 public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float vibration_min, float vibration_max, float vperiod)
24 {
0b1785e3
AG
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;
a9aad043
AG
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));
d8239019 35
a9aad043
AG
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
68float distfromcirclecenter(float px, float py, float pz, float f1x, float f1y, float f1z)
69{
0b1785e3
AG
70 return dist(px, py, pz, f1x, f1y, f1z);
71 }
c2f643bd 72 //void updatespherey(deltaMs, )
a9aad043
AG
73 color spheryvalue (float px, float py, float pz , float f1xc, float f1yc, float f1zc)
74 {
75//switch(sShpape.cur() ) {}
a41f334c 76 return lx.hsb(constrain(huespread.getValuef()*5*px, 0, 360) , dist(px, py, pz, f1xc, f1yc, f1zc) ,
a9aad043
AG
77 max(0, 100 - 100*widthparameter.getValuef()*abs(dist(px, py, pz, f1xcenter, ybounce.getValuef(), f1zcenter)
78 - vibration.getValuef() ) ) );
0b1785e3 79 }
a9aad043
AG
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() ) {}
a41f334c 83 return lx.hsb(huespread.getValuef()*5*px, dist(model.xMax-px, model.yMax-py, model.zMax-pz, f1xc, f1yc, f1zc) ,
a9aad043
AG
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() ) ) ) ;
0b1785e3 88 }
a9aad043 89
d8239019
AG
90void run(double deltaMs) {
91 float vv = vibration.getValuef();
92 float ybv = ybounce.getValuef();
93
94 }
0b1785e3 95
a9aad043
AG
96}
97
98
0b1785e3 99final Sphery[] spherys;
a9aad043
AG
100 SineSphere(GLucose glucose)
101 {
0b1785e3 102 super(glucose);
d8239019
AG
103 sinespin = new Projection(model);
104 addModulator(yrot).trigger();
b30f14fd 105 //Sshape = addPick("Shape", , 1);
a9aad043
AG
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 };
c2f643bd 111
0b1785e3
AG
112 }
113
a9aad043
AG
114// public void onParameterChanged(LXParameter parameter)
115// {
e28f168c 116
e28f168c 117
a9aad043
AG
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// }
e28f168c 133
d8239019 134 void run( double deltaMs) {
a9aad043
AG
135 float t = lx.tempo.rampf();
136 float bpm = lx.tempo.bpmf();
137 //spherys[1].run(deltaMs);
138 //spherys[2].run(deltaMs);
d8239019
AG
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
e28f168c 160
e27a8652 161
a9aad043
AG
162 }
163 int spheremode = 0;
e27a8652 164
a9aad043
AG
165 // void keyPressed() {
166 // spheremode++;
167 // }
e28f168c 168
d8239019
AG
169 // color CalcPoint(PVector Px)
170 // {
171 // // if (spheremode == 0 )
a9aad043 172 //{
d8239019 173
a9aad043
AG
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 // }
a41f334c 182 // return lx.hsb(0,0,0);
a9aad043
AG
183 // // else if(spheremode ==2)
184 // { color c = 0;
a41f334c 185 // return lx.hsb(CalcCone( (xyz by = new xyz(0,spherys[2].ybounce.getValuef(),0) ), Px, mid) );
a9aad043
AG
186
187 // }
188
189
d8239019 190 // }
a9aad043
AG
191
192 }
193
5bc92bc2 194class CubeCurl extends SCPattern{
b30f14fd
AG
195float CH, CW, diag;
196ArrayList<PVector> cubeorigin = new ArrayList<PVector>();
197ArrayList<PVector> centerlist = new ArrayList<PVector>();
5bc92bc2
AG
198private SinLFO curl = new SinLFO(0, Cube.EDGE_HEIGHT, 5000 );
199
200private SinLFO bg = new SinLFO(180, 220, 3000);
201
202CubeCurl(GLucose glucose){
203super(glucose);
204addModulator(curl).trigger();
205addModulator(bg).trigger();
7c7625ec
AG
206 this.CH = Cube.EDGE_HEIGHT;
207 this.CW = Cube.EDGE_WIDTH;
f1370a0b 208 this.diag = sqrt(CW*CW + CW*CW);
b30f14fd 209
7c7625ec 210
b30f14fd 211ArrayList<PVector> centerlistrelative = new ArrayList<PVector>();
7c7625ec 212for (int i = 0; i < model.cubes.size(); i++){
b30f14fd
AG
213 Cube a = model.cubes.get(i);
214 cubeorigin.add(new PVector(a.x, a.y, a.z));
7c7625ec 215 centerlist.add(centerofcube(i));
b30f14fd
AG
216
217}
5bc92bc2
AG
218
219}
7c7625ec
AG
220//there is definitely a better way of doing this!
221PVector centerofcube(int i) {
222Cube c = model.cubes.get(i);
f1370a0b
AG
223
224println(" cube #: " + i + " c.x " + c.x + " c.y " + c.y + " c.z " + c.z );
7c7625ec 225PVector cubeangle = new PVector(c.rx, c.ry, c.rz);
f1370a0b
AG
226//println("raw x" + cubeangle.x + "raw y" + cubeangle.y + "raw z" + cubeangle.z);
227PVector cubecenter = new PVector(c.x + CW/2, c.y + CH/2, c.z + CW/2);
228println("cubecenter unrotated: " + cubecenter.x + " " +cubecenter.y + " " +cubecenter.z );
229PVector 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
231cubecenter = PVector.add(cubecenter, centerrot);
232println( " cubecenter.x " + cubecenter.x + " cubecenter.y " + cubecenter.y + " cubecenter.z " + cubecenter.z + " ");
233
234
b30f14fd 235return cubecenter;
7c7625ec
AG
236}
237
5bc92bc2
AG
238
239void run(double deltaMs){
240for (int i =0; i < model.cubes.size(); i++) {
241Cube c = model.cubes.get(i);
242float cfloor = c.y;
243
f1370a0b 244// if (i%3 == 0){
5bc92bc2 245
f1370a0b
AG
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// }
5bc92bc2 252
f1370a0b 253// else if (i%3 == 1) {
5bc92bc2 254
f1370a0b
AG
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){
b30f14fd 265 // centerlist[i].sub(cubeorigin(i);
5bc92bc2 266 for (Point p: c.points) {
b30f14fd 267 PVector pv = new PVector(p.x, p.y, p.z);
f1370a0b 268 colors[p.index] =color( constrain(4* pv.dist(centerlist.get(i)), 0, 360) , 50, 100 );
b30f14fd 269 // colors[p.index] =color(constrain(centerlist[i].x, 0, 360), constrain(centerlist[i].y, 0, 100), );
5bc92bc2
AG
270
271
b30f14fd 272 }
5bc92bc2
AG
273
274
f1370a0b 275 //}
5bc92bc2
AG
276
277 }
278 }
279 }
280
a9aad043
AG
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
286HueTestHSB(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;
a41f334c 296 c = blendColor(c, lx.hsb(360*HueT.getValuef(), 100*SatT.getValuef(), 100*BriT.getValuef()), ADD);
a9aad043
AG
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 }
0b1785e3 305
a41f334c 306 }