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