| 1 | class SineSphere extends SCPattern { |
| 2 | private SinLFO yrot = new SinLFO(0, TWO_PI, 2000); |
| 3 | public final Projection sinespin; |
| 4 | float modelrad = sqrt((model.xMax)*(model.xMax) + (model.yMax)*(model.yMax) + (model.zMax)*(model.zMax)); |
| 5 | Pick Sshape; |
| 6 | public final PVector P = new PVector(); |
| 7 | |
| 8 | class Sphery { |
| 9 | float f1xcenter, f1ycenter, f1zcenter, f2xcenter , f2ycenter, f2zcenter; //second three are for an ellipse with two foci |
| 10 | private SinLFO vibration; |
| 11 | private SinLFO surface; |
| 12 | private SinLFO vx; |
| 13 | private SinLFO xbounce; |
| 14 | public SinLFO ybounce; |
| 15 | private SinLFO zbounce; |
| 16 | float vibration_min, vibration_max, vperiod; |
| 17 | public BasicParameter widthparameter; |
| 18 | public BasicParameter huespread; |
| 19 | public BasicParameter bouncerate; |
| 20 | public BasicParameter bounceamp; |
| 21 | |
| 22 | public Sphery(float f1xcenter, float f1ycenter, float f1zcenter, float vibration_min, float vibration_max, float vperiod) |
| 23 | { |
| 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; |
| 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)); |
| 34 | |
| 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); |
| 41 | |
| 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 | { |
| 69 | return dist(px, py, pz, f1x, f1y, f1z); |
| 70 | } |
| 71 | //void updatespherey(deltaMs, ) |
| 72 | color spheryvalue (float px, float py, float pz , float f1xc, float f1yc, float f1zc) |
| 73 | { |
| 74 | //switch(sShpape.cur() ) {} |
| 75 | return lx.hsb(constrain(huespread.getValuef()*5*px, 0, 360) , dist(px, py, pz, f1xc, f1yc, f1zc) , |
| 76 | max(0, 100 - 100*widthparameter.getValuef()*abs(dist(px, py, pz, f1xcenter, ybounce.getValuef(), f1zcenter) |
| 77 | - vibration.getValuef() ) ) ); |
| 78 | } |
| 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() ) {} |
| 82 | return lx.hsb(huespread.getValuef()*5*px, dist(model.xMax-px, model.yMax-py, model.zMax-pz, f1xc, f1yc, f1zc) , |
| 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() ) ) ) ; |
| 87 | } |
| 88 | |
| 89 | void run(double deltaMs) { |
| 90 | float vv = vibration.getValuef(); |
| 91 | float ybv = ybounce.getValuef(); |
| 92 | |
| 93 | } |
| 94 | |
| 95 | } |
| 96 | |
| 97 | |
| 98 | final Sphery[] spherys; |
| 99 | SineSphere(GLucose glucose) |
| 100 | { |
| 101 | super(glucose); |
| 102 | sinespin = new Projection(model); |
| 103 | addModulator(yrot).trigger(); |
| 104 | //Sshape = addPick("Shape", , 1); |
| 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 | }; |
| 110 | |
| 111 | } |
| 112 | |
| 113 | // public void onParameterChanged(LXParameter parameter) |
| 114 | // { |
| 115 | |
| 116 | |
| 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 | // } |
| 132 | |
| 133 | void run( double deltaMs) { |
| 134 | float t = lx.tempo.rampf(); |
| 135 | float bpm = lx.tempo.bpmf(); |
| 136 | //spherys[1].run(deltaMs); |
| 137 | //spherys[2].run(deltaMs); |
| 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 | |
| 159 | |
| 160 | |
| 161 | } |
| 162 | int spheremode = 0; |
| 163 | |
| 164 | // void keyPressed() { |
| 165 | // spheremode++; |
| 166 | // } |
| 167 | |
| 168 | // color CalcPoint(PVector Px) |
| 169 | // { |
| 170 | // // if (spheremode == 0 ) |
| 171 | //{ |
| 172 | |
| 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 | // } |
| 181 | // return lx.hsb(0,0,0); |
| 182 | // // else if(spheremode ==2) |
| 183 | // { color c = 0; |
| 184 | // return lx.hsb(CalcCone( (xyz by = new xyz(0,spherys[2].ybounce.getValuef(),0) ), Px, mid) ); |
| 185 | |
| 186 | // } |
| 187 | |
| 188 | |
| 189 | // } |
| 190 | |
| 191 | } |
| 192 | |
| 193 | class CubeCurl extends SCPattern{ |
| 194 | float CH, CW, diag; |
| 195 | ArrayList<PVector> cubeorigin = new ArrayList<PVector>(); |
| 196 | ArrayList<PVector> centerlist = new ArrayList<PVector>(); |
| 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(); |
| 205 | this.CH = Cube.EDGE_HEIGHT; |
| 206 | this.CW = Cube.EDGE_WIDTH; |
| 207 | this.diag = sqrt(CW*CW + CW*CW); |
| 208 | |
| 209 | |
| 210 | ArrayList<PVector> centerlistrelative = new ArrayList<PVector>(); |
| 211 | for (int i = 0; i < model.cubes.size(); i++){ |
| 212 | Cube a = model.cubes.get(i); |
| 213 | cubeorigin.add(new PVector(a.x, a.y, a.z)); |
| 214 | centerlist.add(centerofcube(i)); |
| 215 | |
| 216 | } |
| 217 | |
| 218 | } |
| 219 | //there is definitely a better way of doing this! |
| 220 | PVector centerofcube(int i) { |
| 221 | Cube c = model.cubes.get(i); |
| 222 | |
| 223 | println(" cube #: " + i + " c.x " + c.x + " c.y " + c.y + " c.z " + c.z ); |
| 224 | PVector cubeangle = new PVector(c.rx, c.ry, c.rz); |
| 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 | |
| 234 | return cubecenter; |
| 235 | } |
| 236 | |
| 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 | |
| 243 | // if (i%3 == 0){ |
| 244 | |
| 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 | // } |
| 251 | |
| 252 | // else if (i%3 == 1) { |
| 253 | |
| 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){ |
| 264 | // centerlist[i].sub(cubeorigin(i); |
| 265 | for (Point p: c.points) { |
| 266 | PVector pv = new PVector(p.x, p.y, p.z); |
| 267 | colors[p.index] =color( constrain(4* pv.dist(centerlist.get(i)), 0, 360) , 50, 100 ); |
| 268 | // colors[p.index] =color(constrain(centerlist[i].x, 0, 360), constrain(centerlist[i].y, 0, 100), ); |
| 269 | |
| 270 | |
| 271 | } |
| 272 | |
| 273 | |
| 274 | //} |
| 275 | |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | |
| 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; |
| 295 | c = blendColor(c, lx.hsb(360*HueT.getValuef(), 100*SatT.getValuef(), 100*BriT.getValuef()), ADD); |
| 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 | } |
| 304 | |
| 305 | } |