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