Commit | Line | Data |
---|---|---|
1d414e45 | 1 | class SineSphere extends DPat { |
38712136 | 2 | private SawLFO yrot = new SawLFO(0, TWO_PI, 3000); |
d8239019 | 3 | public final Projection sinespin; |
1d414e45 | 4 | private BasicParameter rotation = new BasicParameter("rotation", 0); |
a9aad043 | 5 | float modelrad = sqrt((model.xMax)*(model.xMax) + (model.yMax)*(model.yMax) + (model.zMax)*(model.zMax)); |
a9aad043 | 6 | Pick Sshape; |
f8295971 | 7 | public final PVector P = new PVector(); |
a9aad043 | 8 | |
0b1785e3 | 9 | class Sphery { |
a9aad043 | 10 | float f1xcenter, f1ycenter, f1zcenter, f2xcenter , f2ycenter, f2zcenter; //second three are for an ellipse with two foci |
0b1785e3 AG |
11 | private SinLFO vibration; |
12 | private SinLFO surface; | |
13 | private SinLFO vx; | |
a9aad043 AG |
14 | private SinLFO xbounce; |
15 | public SinLFO ybounce; | |
16 | private SinLFO zbounce; | |
0b1785e3 | 17 | float vibration_min, vibration_max, vperiod; |
a9aad043 AG |
18 | public BasicParameter widthparameter; |
19 | public BasicParameter huespread; | |
20 | public BasicParameter bouncerate; | |
21 | public BasicParameter bounceamp; | |
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; | |
1d414e45 AG |
31 | //addParameter(bounceamp = new BasicParameter("Amp", .5)); |
32 | //addParameter(bouncerate = new BasicParameter("Rate", .5)); //ybounce.modulateDurationBy(bouncerate); | |
a9aad043 AG |
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); | |
f8295971 | 42 | |
a9aad043 AG |
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) | |
38712136 | 46 | |
a9aad043 AG |
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 | { | |
0b1785e3 AG |
71 | return dist(px, py, pz, f1x, f1y, f1z); |
72 | } | |
c2f643bd | 73 | //void updatespherey(deltaMs, ) |
55a56424 | 74 | |
38712136 AG |
75 | int quadrant(PVector q) { |
76 | //float theta = | |
77 | if (q.x > f1xcenter ) {return 140;} | |
55a56424 AG |
78 | else {return 250;} |
79 | ||
80 | ||
81 | ||
82 | } | |
38712136 AG |
83 | color spheryvalue (PVector p, float f1xcenter, float f1ycenter, float f1zcenter) |
84 | { circlecenter = new PVector(f1xcenter, f1ycenter, f1zcenter); | |
a9aad043 | 85 | //switch(sShpape.cur() ) {} |
38712136 AG |
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) | |
a9aad043 | 89 | - vibration.getValuef() ) ) ); |
0b1785e3 | 90 | } |
a9aad043 AG |
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() ) {} | |
a41f334c | 94 | return lx.hsb(huespread.getValuef()*5*px, dist(model.xMax-px, model.yMax-py, model.zMax-pz, f1xc, f1yc, f1zc) , |
a9aad043 AG |
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() ) ) ) ; | |
0b1785e3 | 99 | } |
a9aad043 | 100 | |
d8239019 AG |
101 | void run(double deltaMs) { |
102 | float vv = vibration.getValuef(); | |
103 | float ybv = ybounce.getValuef(); | |
104 | ||
105 | } | |
0b1785e3 | 106 | |
a9aad043 AG |
107 | } |
108 | ||
109 | ||
0b1785e3 | 110 | final Sphery[] spherys; |
1d414e45 | 111 | |
a9aad043 AG |
112 | SineSphere(GLucose glucose) |
113 | { | |
0b1785e3 | 114 | super(glucose); |
d8239019 AG |
115 | sinespin = new Projection(model); |
116 | addModulator(yrot).trigger(); | |
1d414e45 | 117 | addParameter(rotation); |
b30f14fd | 118 | //Sshape = addPick("Shape", , 1); |
a9aad043 AG |
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 | }; | |
c2f643bd | 124 | |
0b1785e3 AG |
125 | } |
126 | ||
a9aad043 AG |
127 | // public void onParameterChanged(LXParameter parameter) |
128 | // { | |
e28f168c | 129 | |
e28f168c | 130 | |
a9aad043 AG |
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 | // } | |
e28f168c | 146 | |
1d414e45 | 147 | public void run( double deltaMs) { |
a9aad043 AG |
148 | float t = lx.tempo.rampf(); |
149 | float bpm = lx.tempo.bpmf(); | |
55a56424 AG |
150 | spherys[0].run(deltaMs); |
151 | spherys[1].run(deltaMs); | |
152 | spherys[2].run(deltaMs); | |
d8239019 AG |
153 | sinespin.reset(model) |
154 | ||
1d414e45 | 155 | // Translate so the center of the car is the origin, offset |
38712136 AG |
156 | .translateCenter(model, 0, 0, 0) |
157 | // .scale(1.3,1.3,1.3) | |
1d414e45 | 158 | // Rotate around the origin (now the center of the car) about an y-vector |
38712136 AG |
159 | .rotate(yrot.getValuef(), 0, 1 , 0) |
160 | .translate(model.cx, model.cy, model.cz); | |
1d414e45 | 161 | |
d8239019 | 162 | |
1d414e45 AG |
163 | //.translateCenter(model, model.cx, , model.cz); |
164 | ||
d8239019 | 165 | |
38712136 AG |
166 | for (Coord p: sinespin) |
167 | // for (Point p: model.points) | |
1d414e45 | 168 | { |
38712136 | 169 | PVector P = new PVector(p.x, p.y, p.z); |
d8239019 | 170 | color c = 0; |
38712136 AG |
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); | |
d8239019 AG |
174 | |
175 | colors[p.index] = lx.hsb(lx.h(c), lx.s(c), lx.b(c)); | |
176 | ||
177 | } | |
178 | ||
e28f168c | 179 | |
e27a8652 | 180 | |
a9aad043 AG |
181 | } |
182 | int spheremode = 0; | |
e27a8652 | 183 | |
a9aad043 AG |
184 | // void keyPressed() { |
185 | // spheremode++; | |
186 | // } | |
e28f168c | 187 | |
d8239019 AG |
188 | // color CalcPoint(PVector Px) |
189 | // { | |
190 | // // if (spheremode == 0 ) | |
a9aad043 | 191 | //{ |
d8239019 | 192 | |
a9aad043 AG |
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 | // } | |
a41f334c | 201 | // return lx.hsb(0,0,0); |
a9aad043 AG |
202 | // // else if(spheremode ==2) |
203 | // { color c = 0; | |
a41f334c | 204 | // return lx.hsb(CalcCone( (xyz by = new xyz(0,spherys[2].ybounce.getValuef(),0) ), Px, mid) ); |
a9aad043 AG |
205 | |
206 | // } | |
207 | ||
208 | ||
d8239019 | 209 | // } |
a9aad043 AG |
210 | |
211 | } | |
212 | ||
5bc92bc2 | 213 | class CubeCurl extends SCPattern{ |
b30f14fd AG |
214 | float CH, CW, diag; |
215 | ArrayList<PVector> cubeorigin = new ArrayList<PVector>(); | |
216 | ArrayList<PVector> centerlist = new ArrayList<PVector>(); | |
5bc92bc2 AG |
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(); | |
7c7625ec AG |
225 | this.CH = Cube.EDGE_HEIGHT; |
226 | this.CW = Cube.EDGE_WIDTH; | |
f1370a0b | 227 | this.diag = sqrt(CW*CW + CW*CW); |
b30f14fd | 228 | |
7c7625ec | 229 | |
b30f14fd | 230 | ArrayList<PVector> centerlistrelative = new ArrayList<PVector>(); |
7c7625ec | 231 | for (int i = 0; i < model.cubes.size(); i++){ |
b30f14fd AG |
232 | Cube a = model.cubes.get(i); |
233 | cubeorigin.add(new PVector(a.x, a.y, a.z)); | |
7c7625ec | 234 | centerlist.add(centerofcube(i)); |
b30f14fd AG |
235 | |
236 | } | |
5bc92bc2 AG |
237 | |
238 | } | |
7c7625ec AG |
239 | //there is definitely a better way of doing this! |
240 | PVector centerofcube(int i) { | |
241 | Cube c = model.cubes.get(i); | |
f1370a0b AG |
242 | |
243 | println(" cube #: " + i + " c.x " + c.x + " c.y " + c.y + " c.z " + c.z ); | |
1d414e45 AG |
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); | |
f1370a0b AG |
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 ); | |
1d414e45 | 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); |
f1370a0b | 249 | // nCos*(y-o.y) - nSin*(z-o.z) + o.y |
1d414e45 | 250 | cubecenter = PVector.add(new PVector(c.x, c.y, c.z), centerrot); |
f1370a0b AG |
251 | println( " cubecenter.x " + cubecenter.x + " cubecenter.y " + cubecenter.y + " cubecenter.z " + cubecenter.z + " "); |
252 | ||
253 | ||
b30f14fd | 254 | return cubecenter; |
7c7625ec AG |
255 | } |
256 | ||
5bc92bc2 AG |
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 | ||
f1370a0b | 263 | // if (i%3 == 0){ |
5bc92bc2 | 264 | |
f1370a0b AG |
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 | // } | |
5bc92bc2 | 271 | |
f1370a0b | 272 | // else if (i%3 == 1) { |
5bc92bc2 | 273 | |
f1370a0b AG |
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){ | |
b30f14fd | 284 | // centerlist[i].sub(cubeorigin(i); |
5bc92bc2 | 285 | for (Point p: c.points) { |
b30f14fd | 286 | PVector pv = new PVector(p.x, p.y, p.z); |
f1370a0b | 287 | colors[p.index] =color( constrain(4* pv.dist(centerlist.get(i)), 0, 360) , 50, 100 ); |
b30f14fd | 288 | // colors[p.index] =color(constrain(centerlist[i].x, 0, 360), constrain(centerlist[i].y, 0, 100), ); |
5bc92bc2 AG |
289 | |
290 | ||
b30f14fd | 291 | } |
5bc92bc2 AG |
292 | |
293 | ||
f1370a0b | 294 | //} |
5bc92bc2 AG |
295 | |
296 | } | |
297 | } | |
298 | } | |
299 | ||
a9aad043 AG |
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; | |
a41f334c | 315 | c = blendColor(c, lx.hsb(360*HueT.getValuef(), 100*SatT.getValuef(), 100*BriT.getValuef()), ADD); |
a9aad043 AG |
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 | } | |
0b1785e3 | 324 | |
a41f334c | 325 | } |