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