X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=DanHorwitz.pde;h=7c6c7f4c24fb177e64b75c14aa3f87bae8249f11;hb=fb83f322926c02562db8c2824f89e4bc9c0cb992;hp=5435e62ed7ab0472ef5911c6f871bad71b446197;hpb=957d253fcdc00ed1abd91594535a16f2d163f760;p=SugarCubes.git diff --git a/DanHorwitz.pde b/DanHorwitz.pde index 5435e62..7c6c7f4 100644 --- a/DanHorwitz.pde +++ b/DanHorwitz.pde @@ -1,276 +1,140 @@ //---------------------------------------------------------------------------------------------------------------------------------- -static MidiOutput midiout; -int nNumRows = 6, nNumCols = 8; -boolean btwn (int a,int b,int c) { return a >= b && a <= c; } - -public class _P extends BasicParameter { - _P(String label, double value) { super(label,value); } - void updateValue (double value) { super.updateValue(value); } - float Val () { return getValuef(); } -} - -public class Pick { - Pick (String label, int _Def, int _Max) { Picks=_Max; Default = _Def; tag=label; } - int Cur() { return (CurCol-StartCol)*nNumRows + CurRow; } - int Picks, Default, CurRow, CurCol, StartCol, EndCol; - String tag; -} -//---------------------------------------------------------------------------------------------------------------------------------- -float xMax,yMax,zMax; -public class xyz { float x,y,z; - xyz() {x=y=z=0;} - xyz(Point p ) {x=p.fx ; y=p.fy; z=p.fz;} - xyz(float _x,float _y,float _z) {x=_x ; y=_y ; z=_z ;} - void set(float _x,float _y,float _z) {x=_x ; y=_y ; z=_z ;} - float distance(xyz b) {return dist(x,y,z,b.x,b.y,b.z); } - float dot (xyz b) {return x*b.x + y*b.y + z*b.z; } - xyz minus (xyz b) {return new xyz(x-b.x,y-b.y,z-b.z); } - xyz plus (xyz b) {return new xyz(x+b.x,y+b.y,z+b.z); } - xyz plus (float b) {return new xyz(x+b ,y+b ,z+b ); } - xyz over (xyz b) {return new xyz(x/b.x,y/b.y,z/b.z); } - xyz times (float b) {return new xyz(x*b ,y*b ,z*b ); } - - xyz RotateX (xyz o, float a) { return new xyz ( x, - cos(a)*(y-o.y) - sin(a)*(z-o.z) + o.y, - sin(a)*(y-o.y) + cos(a)*(z-o.z) + o.z); } - - xyz RotateY (xyz o, float a) { return new xyz ( cos(a)*(x-o.x) - sin(a)*(z-o.z) + o.x, - y, - sin(a)*(x-o.x) + cos(a)*(z-o.z) + o.z); } - - xyz RotateZ (xyz o, float a) { return new xyz ( cos(a)*(x-o.x) - sin(a)*(y-o.y) + o.x, - sin(a)*(x-o.x) + cos(a)*(y-o.y) + o.y, - z ); } - - - xyz setRand () { return new xyz ( random(xMax), random(yMax), random(zMax)); } - xyz setNorm () { return new xyz ( x / xMax, y / yMax, z / zMax); } - - - float interp (float a, float b, float c) { return (1-a)*b + a*c; } - xyz interpolate(float i, xyz d) { return new xyz ( interp(i,x,d.x), interp(i,y,d.y), interp(i,z,d.z)); } -} -//---------------------------------------------------------------------------------------------------------------------------------- -public class hsb { float h,s,b; - hsb(color c) { h=hue(c); s=saturation(c); b=brightness(c); } - color Out() { return color(h%360.,constrain(s,0,100),constrain(b,0,100)); } -} - -public class DPat extends SCPattern -{ - float zSpinHue; - xyz xyzMax, xyz0, xyzMid, xyzHalf; - - ArrayList picks = new ArrayList(); - int nMaxCol = 0; - boolean bIsActive = false; - float Dist (xyz a, xyz b) { return dist(a.x,a.y,a.z,b.x,b.y,b.z); } - float c1c (float a) { return 100*constrain(a,0,1); } - int mapRow (int a) { return a == 52 ? 5 : btwn(a,53,57) ? a-53 : a; } - int unmapRow (int a) { return a == 5 ? 52 : btwn(a,0 , 4) ? a+53 : a; } - void SetLight (int row, int col, int clr){ if (midiout != null) midiout.sendNoteOn(col, unmapRow(row), clr); } - void keypad (int row, int col) {} - void onInactive() { bIsActive=false; } - void onActive () { bIsActive=true; - zSpinHue = 0; - for (int i=0; i0) cNew.b = max(cNew.b,cOld.b - (1-s_Trails()) * deltaMs); - if (s_Dim ()>0) cNew.b *= 1-s_Dim (); - if (s_Saturate ()>0) cNew.s += s_Saturate()*100; - if (s_SpinHue ()>0) cNew.h += zSpinHue; - if (s_ModHue ()>0) cNew.h += s_ModHue()*360; - colors[p.index] = cNew.Out(); - } - } - - void controllerChangeReceived(rwmidi.Controller cc) { - if (cc.getCC() == 7 && btwn(cc.getChannel(),0,7)) Sliders[cc.getChannel()] = 1.*cc.getValue()/127.; - } - - float Sliders[] = new float[] {0,0,0,0,0,0,0,0}; - float s_Trails () { return Sliders[0]; } - float s_Dim () { return Sliders[1]; } - float s_Saturate () { return Sliders[2]; } - float s_SpinHue () { return Sliders[3]; } - float s_ModHue () { return Sliders[4]; } - - DPat(GLucose glucose) { - super(glucose); - xMax = model.xMax; yMax = model.yMax; zMax = model.zMax; - xyzMax = new xyz(xMax,yMax,zMax); - xyzMid = new xyz(xMax/2, yMax/2, zMax/2); - xyzHalf = new xyz(.5,.5,.5); - xyz0 = new xyz(0,0,0); - for (MidiInputDevice input : RWMidi.getInputDevices ()) { if (input.toString().contains("APC")) input .createInput (this);} - for (MidiOutputDevice output : RWMidi.getOutputDevices()) { - if (midiout == null && output.toString().contains("APC")) midiout = output.createOutput(); - } - } - - void UpdateLights(Pick P) { - if (P==null) return; - for (int i=0; i xMax/2) v.x = xMax-v.x; - if ((symm == YSym || symm == XyzSym) && v.y > yMax/2) v.y = yMax-v.y; - if (( symm == XyzSym) && v.z > zMax/2) v.z = zMax-v.z; - - NDat n = (NDat) noises.get(i); - float deg = radians(n.angle + (symm==XyzSym?45:0)); - float zx = zTime * n.speed * sin(deg), - zy = zTime * n.speed * cos(deg), - sharp = 1/constrain(2-n.sharp - 2*pSharp.Val(),0,1); - - float b = (symm==RadSym ? noise(zTime*n.speed+n.xoff-Dist(v,xyzMid)/n.xz) - : noise(v.x/n.xz+zx+n.xoff,v.y/n.yz+zy+n.yoff,v.z/n.zz+n.zoff)) - *1.8-.4 + n.den/100 + pDensity.Val() -1; - - b += n.den/100 + pDensity.Val() -1; - b = b < .5 ? pow(b,sharp) : 1-pow(1-b,sharp); + color CalcPoint(xyz P) { + color c = 0; + P.RotateZ(mCtr, zSin, zCos); + + if (CurAnim == 6 || CurAnim == 7) { + P.setNorm(); + return lx.hsb(0,0, 100 * ( + constrain(1-50*(1-pDensity.Val())*abs(P.y-sin(zTime*10 + P.x*(300))*.5 - .5),0,1) + + (CurAnim == 7 ? constrain(1-50*(1-pDensity.Val())*abs(P.x-sin(zTime*10 + P.y*(300))*.5 - .5),0,1) : 0)) + ); + } + + if (iSymm == XSym && P.x > mMax.x/2) P.x = mMax.x-P.x; + if (iSymm == YSym && P.y > mMax.y/2) P.y = mMax.y-P.y; + + for (int i=0;i<_ND; i++) if (N[i].Active()) { + NDat n = N[i]; + float zx = zTime * n.speed * n.sinAngle, + zy = zTime * n.speed * n.cosAngle; + + float b = (iSymm==RadSym ? noise(zTime*n.speed+n.xoff-Dist(P,mCtr)/n.xz) + : noise(P.x/n.xz+zx+n.xoff,P.y/n.yz+zy+n.yoff,P.z/n.zz+n.zoff)) + *1.8; + + b += n.den/100 -.4 + pDensity.Val() -1; b += transAdd; - c = blendColor(c,color(n.hue,n.sat,c1c(b)),ADD); + c = blendColor(c,color(n.hue,100*n.sat,c1c(b)),ADD); } return c; } @@ -278,94 +142,288 @@ public class Noise extends DPat //---------------------------------------------------------------------------------------------------------------------------------- public class Play extends DPat { + public class rAngle { + float prvA, dstA, c; + float prvR, dstR, r; + float _cos, _sin, x, y; + float fixAngle (float a, float b) { return a abs(a+2*PI-b) ? a : a+2*PI) : + (abs(a-b) > abs(a-2*PI-b) ? a : a-2*PI) ; } + float getX(float r) { return mCtr.x + _cos*r; } + float getY(float r) { return mCtr.y + _sin*r; } + void move() { c = interp(t,prvA,dstA); + r = interp(t,prvR,dstR); + _cos = cos(c); _sin = sin(c); + x = getX(r); y = getY(r); } + void set() { prvA = dstA; dstA = random(2*PI); prvA = fixAngle(prvA, dstA); + prvR = dstR; dstR = random(mCtr.y); } + } + int nBeats = 0; - _P pAmp, pRotX, pRotY, pRotZ, pRad; + DParam pAmp, pRadius, pBounce; + + float t,amp,rad,bnc; + float zTheta=0; + ArrayList waves = new ArrayList(10); + + rAngle a1 = new rAngle(), a2 = new rAngle(), + a3 = new rAngle(), a4 = new rAngle(); + xyz cPrev = new xyz(), cRand = new xyz(), + cMid = new xyz(), V = new xyz(), + Theta = new xyz(), TSin = new xyz(), + TCos = new xyz(), cMidNorm = new xyz(), + Pn = new xyz(); + float LastBeat=3, LastMeasure=3; + int CurRandTempo = 1, CurRandTPat = 1; + Pick pTimePattern, pTempoMult, pShape; + int RandCube; Play(GLucose glucose) { super(glucose); - addParameter(pAmp = new _P("Amp" , .2 )); - addParameter(pRotX = new _P("RotX", 0 )); - addParameter(pRotY = new _P("RotY", 0 )); - addParameter(pRotZ = new _P("RotZ", 0 )); - addParameter(pRad = new _P("Rad" , .1 )); - - pTimePattern = addPick("TPat", 0 , 5 ); - pTempoMult = addPick("TMul", 5 , 6 ); - pShape = addPick("Shap", 8 , 10 ); + pRadius = addParam("Rad" , .1 ); + pBounce = addParam("Bnc" , .2 ); + pAmp = addParam("Amp" , .2 ); + pTempoMult = addPick ("TMult" , 0 , 5 , new String[] {"1x", "2x", "4x", "8x", "16x", "Rand" } ); + pTimePattern= addPick ("TPat" , 6 , 7 , new String[] {"Bounce", "Sin", "Roll", "Quant", "Accel", "Deccel", "Slide", "Rand"} ); + pShape = addPick ("Shape" , 3 , 15 , new String[] {"Line", "Tap", "V", "RandV", + "Pyramid", "Wings", "W2", "Clock", + "Triangle", "Quad", "Sphere", "Cone", + "Noise", "Wave", "?", "?"} ); + } - lx.tempo.setBpm(30); + public class rWave { + float v0, a0, x0, t,damp,a; + boolean bDone=false; + final float len=8; + rWave(float _x0, float _a0, float _v0, float _damp) { x0=_x0*len; a0=_a0; v0=_v0; t=0; damp = _damp; } + void move(double deltaMs) { + t += deltaMs*.001; + if (t>4) bDone=true; + } + float val(float _x) { + _x*=len; + float dist = t*v0 - abs(_x-x0); + if (dist<0) { a=1; return 0; } + a = a0*exp(-dist*damp) * exp(-abs(_x-x0)/(.2*len)); // * max(0,1-t/dur) + return -a*sin(dist); + } } - float t,a; - xyz cPrev = new xyz(), cCur = new xyz(), cMid = new xyz(), cMidNorm; - float LastBeat=3, LastMeasure=3; - int CurRandTempo = 1; - - void StartRun(int deltaMs) { - t = lx.tempo.rampf(); - a = pAmp.Val(); - - if (t 6 ? 2+int(random(5)) : int(random(7)); } + } LastMeasure = t; + + int nTempo = pTempoMult .Cur(); if (nTempo == 5) nTempo = CurRandTempo; + int nTPat = pTimePattern.Cur(); if (nTPat == 7) nTPat = CurRandTPat ; + + switch (nTempo) { case 0: t = t; break; case 1: t = (t*2. )%1.; break; case 2: t = (t*4. )%1.; break; case 3: t = (t*8. )%1.; break; case 4: t = (t*16.)%1.; break; - case 5: t = (t*pow(2,CurRandTempo))%1.; break; } - if (t-1) { + waves.add(new rWave( + pKey.b ? map(DG.KeyPressed,0,7,0,1) : random(1), // location + bnc*10, // bounciness + 7, // velocity + 2*(1-amp))); // dampiness + DG.KeyPressed=-1; + if (waves.size() > 5) waves.remove(0); + } + + if (t .5?1:0)); // cone + + case 12: return lx.hsb(100 + noise(Pn.x,Pn.y,Pn.z + (NoiseMove+50000)/1000.)*200, + 85,c1c(Pn.y < noise(Pn.x + NoiseMove/2000.,Pn.z)*(1+amp)-amp/2.-.1 ? 1 : 0)); // noise + + case 13: float y=0; for (rWave w : waves) y += .5*w.val(Pn.x); + V.set(Pn.x, .7+y, Pn.z); + break; + + default: return lx.hsb(0,0,0); + } - case 4: V = new xyz(P.x, .5*(P.x < cMidNorm.x ? map(P.x,0,cMidNorm.x, .5,yt) : - map(P.x,cMidNorm.x,1, yt,.5)) + - .5*(P.z < cMidNorm.z ? map(P.z,0,cMidNorm.z, .5,yt) : - map(P.z,cMidNorm.z,1, yt,.5)), P.z); break; // Random Pyramid shape - - case 5: V = new xyz(P.x, a*map((P.x-.5)*(P.x-.5),0,.25,0,t-.5)+.5, P.z); break; // wings - case 6: V = new xyz(P.x, a*map((mp -.5)*(mp -.5),0,.25,0,t-.5)+.5, P.z); break; // wings + return lx.hsb(0, + 150-c1c(1 - V.distance(Pn)/rad), + c1c(1 - V.distance(Pn)/rad)); + } +} +//---------------------------------------------------------------------------------------------------------------------------------- +// 0 - TLB, L (b), BLB, B (l) // Fwd , Down, Back, Up +// 4 - TLF, F (l), BLF, L (f) // Fwd , Down, Back, Up +// 8 - TRF, R (f), BRF, F (r) // Back, Down, Fwd , Up +// 12- TRB, B (r), BRB, R (b) // Back, Down, Fwd , Up +// 1->7, 15->9 +int randDir() { return round(random(1))*2-1; } +//---------------------------------------------------------------------------------------------------------------------------------- +boolean dDebug = true; +class dCursor { + dVertex v, vNext; + int pos,posNext; // 0 - 65535 + int stop; // 0-15 + color clr; + + dCursor(color _c) { clr=_c;} + + boolean isDone() { return pos==stop<<12; } + void set(dVertex _v, int _pos) { pos = _pos; v = _v; vNext = null; stop=16; } + + boolean Turn(dTurn t) { + if (t.pos0<<12 < pos) return false; + vNext = t.v; + stop = t.pos0; + posNext = t.pos1<<12; + if (randDir()<0) { vNext = t.v.opp; posNext = (16<<12)-posNext; } + return true; + } - case 7: V = new xyz(cMid.x,cMid.y,cMid.z); - return color(0,0,c1c(1 - (V.distance(Px) > (pRad.getValuef()+.1)*100?1:0)) ); // sphere + void PickNext() { + if (vNext != null) { set(vNext, posNext); } + else { set(random(2) < 1 ? v.c0 : v.c1, 0); } + // plan to turn the corner + float r = random(3); + if (r<1 && v.t0 != null && Turn(v.t0)) return; + if (r<2 && v.t1 != null && Turn(v.t1)) return; + } + Point p1, p2; int i2; +} - case 8: V = new xyz(cMid.x,cMid.y,cMid.z); - return color(0,0,c1c(1 - CalcCone(Px,V,xyzMid) * 0.02 > .5?1:0)); // cone +//---------------------------------------------------------------------------------------------------------------------------------- +class Worms extends SCPattern { + float StripsPerSec = 10; + float TrailTime = 1000; + int Cursors = 25; + dCursor cur[] = new dCursor[Cursors]; + + int draw(dCursor c, int nAmount) { + int nFrom = (c.pos ) >> 12; + int nMv = min(nAmount, (c.stop<<12)-c.pos); + int nTo = min(15,(c.pos+nMv) >> 12); + + if (dDebug) { c.p1 = c.v.getPoint(nFrom); float d = (c.p2 == null ? 0 : PointDist(c.p1,c.p2)); if (d>5) { println("too wide! quitting: " + d); exit(); }} + for (int i = nFrom; i <= nTo; i++) { colors[c.v.ci + c.v.dir*i ] = c.clr; } + if (c.v.same != null) for (int i = nFrom; i <= nTo; i++) { colors[c.v.same.ci + c.v.same.dir*i] = c.clr; } + if (dDebug) { c.p2 = c.v.getPoint(nTo); c.i2 = nTo; } + + c.pos += nMv; return nAmount - nMv; + } + Worms(GLucose glucose) { + super(glucose); + if (DL_ == null) DL_ = new dLattice(); + for (int i=0; i0) colors[i] = color(hue(c), saturation(c), (float)(b-100*deltaMs/TrailTime)); } - return color(0,0,c1c(1 - V.distance(P)/pRad.getValuef() > .5?1:0)); + for (int i=0; i 0) { nLeft = draw(cur[i], nLeft); if (cur[i].isDone()) cur[i].PickNext(); } + } } } -//---------------------------------------------------------------------------------------------------------------------------------- \ No newline at end of file +//----------------------------------------------------------------------------------------------------------------------------------