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