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