X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=DanHorwitz.pde;h=d084609e620c2dde46d31ce2e02c09f674da5ffe;hb=7c7625ec088b93148f46adc19ba8f1cb4baa8321;hp=96101809f59680b0bf91b23f0d156db0f04ddc2f;hpb=4404e6b81ef8713c47d8cc1e519be83bbbe5a87b;p=SugarCubes.git diff --git a/DanHorwitz.pde b/DanHorwitz.pde index 9610180..d084609 100755 --- a/DanHorwitz.pde +++ b/DanHorwitz.pde @@ -15,12 +15,13 @@ public class Pong extends DPat { addModulator(y = new SinLFO(cRad, mMax.y - cRad, 0)).trigger(); y.modulateDurationBy(dy); addModulator(z = new SinLFO(cRad, mMax.z - cRad, 0)).trigger(); z.modulateDurationBy(dz); pSize = addParam ("Size" , 0.4 ); - pChoose = addPick ("Animiation" , 0 , 3, new String[] {"Pong", "Ball", "Cone"} ); + pChoose = addPick ("Animiation" , 0, 2, new String[] {"Pong", "Ball", "Cone"} ); } void StartRun(double deltaMs) { cRad = mMax.x*pSize.Val()/6; } color CalcPoint(xyz p) { v.set(x.getValuef(), y.getValuef(), z.getValuef()); + v.z=0;p.z=0;// ignore z dimension switch(pChoose.Cur()) { case 0: vMir.set(mMax); vMir.subtract(p); return color(0,0,c1c(1 - min(v.distance(p), v.distance(vMir))*.5/cRad)); // balls @@ -50,25 +51,25 @@ public class Noise extends DPat { int CurAnim, iSymm; int XSym=1,YSym=2,RadSym=3; - float zTime = random(10000), zTheta=0, zSin, zCos; - float rtime = 0, ttime = 0, transAdd=0; - DParam pSpeed , pDensity, pRotZ; + float zTime , zTheta=0, zSin, zCos, rtime, ttime, transAdd; + DParam pSpeed , pDensity; Pick pChoose, pSymm; int _ND = 4; NDat N[] = new NDat[_ND]; Noise(GLucose glucose) { super(glucose); - pRotZ = addParam("RotZ" , .5 ); pSpeed = addParam("Fast", .55); - pDensity= addParam("Dens" , .5); - pSymm = addPick("Symmetry" , 0, 4, new String[] {"None", "X", "Y", "Radial"} ); - pChoose = addPick("Animation", 1, 6, new String[] {"Drip", "Cloud", "Rain", "Fire", "Machine", "Spark"} ); + pSpeed = addParam("Fast" , .55); + pDensity = addParam("Dens" , .5); + pSymm = addPick("Symmetry" , 0, 3, new String[] {"None", "X", "Y", "Radial"} ); + pChoose = addPick("Animation", 6, 7, new String[] {"Drip", "Cloud", "Rain", "Fire", "Machine", "Spark","VWave", "Wave"} ); for (int i=0; i<_ND; i++) N[i] = new NDat(); } + void StartPattern() { zTime = random(500); zTheta=0; rtime = 0; ttime = 0; transAdd=0; } void StartRun(double deltaMs) { zTime += deltaMs*(pSpeed.Val()-.5)*.002 ; - zTheta += deltaMs*(pRotZ .Val()-.5)*.01 ; + zTheta += deltaMs*(pSpin .Val()-.5)*.01 ; rtime += deltaMs; iSymm = pSymm.Cur(); transAdd = 1*(1 - constrain(rtime - ttime,0,1000)/1000); @@ -77,8 +78,8 @@ public class Noise extends DPat if (pChoose.Cur() != CurAnim) { CurAnim = pChoose.Cur(); ttime = rtime; - pRotZ .reset(); zTheta = 0; - pDensity .reset(); pSpeed .reset(); + pSpin .reset(); zTheta = 0; + pDensity .reset(); pSpeed .reset(); for (int i=0; i<_ND; i++) { N[i].isActive = false; } switch(CurAnim) { @@ -111,6 +112,14 @@ public class Noise extends DPat color c = 0; P.RotateZ(mCtr, zSin, zCos); + if (CurAnim == 6 || CurAnim == 7) { + P.setNorm(); + return color(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; @@ -149,11 +158,14 @@ public class Play extends DPat void set() { prvA = dstA; dstA = random(2*PI); prvA = fixAngle(prvA, dstA); prvR = dstR; dstR = random(mCtr.y); } } + int nBeats = 0; - DParam pAmp, pRad; - DParam pRotX, pRotY, pRotZ; + DParam pAmp, pRadius, pBounce; + + float t,amp,rad,bnc; + float zTheta=0; + ArrayList waves = new ArrayList(10); - float t,amp; rAngle a1 = new rAngle(), a2 = new rAngle(), a3 = new rAngle(), a4 = new rAngle(); xyz cPrev = new xyz(), cRand = new xyz(), @@ -164,28 +176,49 @@ public class Play extends DPat float LastBeat=3, LastMeasure=3; int CurRandTempo = 1, CurRandTPat = 1; - - Pick pTimePattern, pTempoMult, pShape, pForm; + Pick pTimePattern, pTempoMult, pShape; int RandCube; Play(GLucose glucose) { super(glucose); - pRotX = addParam("RotX", .5); - pRotY = addParam("RotY", .5); - pRotZ = addParam("RotZ", .5); - pAmp = addParam("Amp" , .2); - pRad = addParam("Rad" , .1 ); - pTempoMult = addPick ("TMult" , 0 , 6 , new String[] {"1x", "2x", "4x", "8x", "16x", "Rand" } ); - pTimePattern= addPick ("TPat" , 6 , 8 , new String[] {"Bounce", "Sin", "Roll", "Quant", "Accel", "Deccel", "Slide", "Rand"} ); pShape = addPick ("Shape" , 8 , 12 , new String[] {"Line", "Tap", "V", "RandV", "Pyramid", "Wings", "W2", "Clock", - "RSphere", "Sphere", "Cone", "Noise" } ); - pForm = addPick ("Form" , 0 , 3 , new String[] {"Bar", "Volume", "Fade"} ); + 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", "?", "?"} ); } + 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); + } + } + + void StartPattern() { zTheta=0; } void StartRun(double deltaMs) { t = lx.tempo.rampf(); amp = pAmp.Val(); + rad = pRadius.getValuef(); + bnc = pBounce.getValuef(); + zTheta += deltaMs*(pSpin .Val()-.5)*.01; - Theta .set(pRotX.Val()*PI*2, pRotY.Val()*PI*2, pRotZ.Val()*PI*2); + Theta .set(pRotX.Val()*PI*2, pRotY.Val()*PI*2, pRotZ.Val()*PI*2 + zTheta); TSin .set(sin(Theta.x), sin(Theta.y), sin(Theta.z)); TCos .set(cos(Theta.x), cos(Theta.y), cos(Theta.z)); @@ -205,6 +238,21 @@ public class Play extends DPat case 4: t = (t*16.)%1.; break; } + int i=0; while (i< waves.size()) { + rWave w = waves.get(i); + w.move(deltaMs); if (w.bDone) waves.remove(i); else i++; + } + + 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 11: + Px.z=mCtr.z; cMid.z=mCtr.z; + return color(0,0,c1c(1 - CalcCone(Px,cMid,mCtr) * 0.02 > .5?1:0)); // cone - case 11: return color(100 + noise(Pn.x,Pn.y,Pn.z + (NoiseMove+50000)/1000.)*200, + case 12: return color(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 color(0,0,0); } - switch (pForm.Cur()) { - case 0: return color(0,0,c1c(1 - V.distance(Pn)/rad > .5?1:0)); - case 1: return color(0,0,c1c(Pn.y < V.y ?1:0)); - case 2: return color(0,0,c1c(1 - V.distance(Pn)/rad)); + return color(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 + +class dBolt { + dStrip v, h; + int vpos, hpos; + dBolt(dStrip _v, dStrip _h, int _vpos, int _hpos) { + v=_v; h=_h; vpos=_vpos; hpos=_hpos; + if (v.b0 == null) { v.b0=this; h.b0=this; } + else { v.b1=this; h.b1=this; } + } +} + +class dVertex { + dStrip s1 , s2 ; + int dir1, dir2 ; + dVertex(dStrip s, int d) { + int _a = (s.iS%4==1)? (d==1? 5: 3) : + (s.iS%4==3)? (d==1? 9:11) : + (d==1) ? (s.Top()?4:12) : (s.Top()?12:4); + dir1 = d * (s.isVert() ? -1 : 1); + dir2 = d; + s1 = DL_.DS[s.iCube() + ((s.iS+_a) % 16)]; + s2 = DL_.DS[d == 1 ? (s.idx == s.iFace()+3 ? s.idx-3 : s.idx+1): + (s.idx == s.iFace() ? s.idx+3 : s.idx-1)]; + swapout(1 , 6); + swapout(15,-6); + } + void swapout(int a, int b) { + if (s1.iS == a) { s1 = DL_.DS[s1.idx + b]; dir1 = -dir1; } + if (s2.iS == a) { s2 = DL_.DS[s2.idx + b]; dir2 = -dir2; } + } + +} + +class dStrip { // THIS WAS SUCH A PAIN! + int row, col, ci, idx, iS, axis; // 1-y, 2-left, 3-right + Strip s; + boolean bTop; // direction: top ccw, bottom cw. + + boolean Top (){ return axis!=1 && bTop ; } + boolean Bottom(){ return axis!=1 && !bTop; } + boolean isVert(){ return axis==1; } + boolean isHorz(){ return axis!=1; } + int iCube (){ return 16*floor(idx/16); } + int iFace (){ return iCube() + 4*floor(iS/4); } + + void init(Strip _s, int _i, int _row, int _col) { + idx = _i; row = _row; col = _col; s = _s; + iS = idx%16; bTop = (iS%4==0); + ci = s.points.get(0).index; + DL_.DQ[col][row] = iCube(); + switch (iS) { + case 4: case 6 : case 12: case 14: axis=2; break; + case 0: case 2 : case 8 : case 10: axis=3; break; + default: axis=1; break; + } + } + + void addBolts() { + v0 = new dVertex(this, 1); + v1 = new dVertex(this,-1); + - default: return color(0,0,c1c(Pn.y < V.y ?1:0)); + if (iS == 7 && col != 0 && row != 0) // left bottom + new dBolt(this, DL_.GetStrip(row-1,col-1,(col % 2 == 1) ? 8 : 12), + 4, (col % 2 == 1) ? 6 : 9); + + if (iS == 7 && col != 0 && row < MaxCubeHeight*2-2) // left top + new dBolt(this, DL_.GetStrip(row+1,col-1,(col % 2 == 1) ? 10 : 14), + 11, (col % 2 == 1) ? 9 : 6); + + if (iS == 9 && col < NumBackTowers-1 && row < MaxCubeHeight*2-2) // right top + new dBolt(this, DL_.GetStrip(row+1,col+1,(col % 2 == 1) ? 6 : 2), + 4, (col % 2 == 1) ? 6 : 9); + + if (iS == 9 && col < NumBackTowers-1 && row != 0) // right bottom + new dBolt(this, DL_.GetStrip(row-1,col+1,(col % 2 == 1) ? 4 : 0), + 11, (col % 2 == 1) ? 9 : 6); + } + + dBolt b0, b1; + dVertex v0, v1; +} + +class dCursor { + dStrip s, sNext; + int nLast,pos,posNext,end; // 0 - 65535 + int dir; // 1 or -1 + color clr; + + dCursor(color _c) { clr=_c;} + + boolean isDone() { return pos==end; } + void set(dStrip _s, int _dir) { + s=_s; dir=_dir; pos = 0; end=65536; nLast=-1; sNext=null; + } + + boolean MakeTurn(dBolt b) { + int nEnd= (s.isVert() ? b.vpos : b.hpos) <<12; + nEnd= (dir==1 ? nEnd : 65536-nEnd); + if (nEnd < pos) return false; + if (s.isVert()) { sNext = b.h; posNext = b.hpos<<12; end = nEnd; } + else { sNext = b.v; posNext = b.vpos<<12; end = nEnd; } + return true; + } + + void PickNext() { + if (sNext != null) { + if (end == 65536) exit(); + end = 65536; + pos = posNext; + dir = randDir(); + if (dir<0) pos = end-pos; + s = sNext; sNext = null; + nLast = -1; + return;// could switch again!! + } else { + dVertex v = (dir == 1 ? s.v0 : s.v1); + int r = floor(random(2)); + set(r==0 ? v.s1 : v.s2,r==0 ? v.dir1 : v.dir2); + } + + // plan to turn the corner + if (random(6)<1 && s.b0 != null && MakeTurn(s.b0)) return; + if (random(6)<1 && s.b1 != null && MakeTurn(s.b1)) return; + } +} + +int randDir() { return round(random(1))*2-1; } + +class dLattice { + int iTowerStrips=-1; + dStrip[] DS = new dStrip[glucose.model.strips.size()]; + int[][] DQ = new int[NumBackTowers][MaxCubeHeight*2]; + + int nStrips() { return iTowerStrips; } + dStrip GetStrip (int row, int col, int off) { return DS[DQ[col][row]+off]; } + dLattice() { + DL_=this; + int col = 0, row = -2, i=-1; + for (Strip strip : glucose.model.strips ) { i++; + if (i % 16 == 0) row+=2; + if (row >= MaxCubeHeight*2-1) { col++; row = (col%2==1)?1:0; } + if (col >= NumBackTowers) continue; + iTowerStrips++ ; + dStrip s = DS[iTowerStrips] = new dStrip(); + s.init(strip, iTowerStrips, row, col); + } + + for (int j=0; j> 12); + int nTo = min(15,(c.pos+nAmount) >> 12); c.nLast=nTo; + int nMv = min(nAmount, c.end-c.pos); + c.pos += nMv; + for (int i = nFrom; i <= nTo; i++) { + int n = c.s.ci + (c.dir>0 ? i : 15-i); + colors[n] = c.clr; + } + return nAmount - nMv; + } + + float StripsPerSec = 6; + float TrailTime = 1500; + int Cursors = 40; + dCursor cur[] = new dCursor[Cursors]; + + Worms(GLucose glucose) { + super(glucose); + if (DL_ == null) DL_ = new dLattice(); + for (int i=0; i= d.vpos) colors[d.v.ci+i] = color(0,0,30); + if (s == d.h && i >= d.hpos) colors[d.h.ci+i] = color(0,0,30); + }} + } + } else { + for (int i=0; i 0) { + nLeft = draw(cur[i], nLeft); + if (cur[i].isDone()) cur[i].PickNext(); + } + } + + for (int i=0,s=model.points.size(); i0) colors[i] = color(hue(c), saturation(c), + (float)(b-100*deltaMs/TrailTime)); + } } } }