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