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