From: bb3dan Date: Fri, 27 Sep 2013 01:30:29 +0000 (-0400) Subject: more dpat fixes X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=4404e6b81ef8713c47d8cc1e519be83bbbe5a87b;p=SugarCubes.git more dpat fixes --- diff --git a/DanHorwitz.pde b/DanHorwitz.pde index a51f0a4..9610180 100755 --- a/DanHorwitz.pde +++ b/DanHorwitz.pde @@ -7,25 +7,25 @@ public class Pong extends DPat { Pong(GLucose glucose) { super(glucose); - cRad = xdMax/15; + cRad = mMax.x/10; addModulator(dx = new SinLFO(6000, 500, 30000 )).trigger(); addModulator(dy = new SinLFO(3000, 500, 22472 )).trigger(); addModulator(dz = new SinLFO(1000, 500, 18420 )).trigger(); - addModulator(x = new SinLFO(cRad, xdMax - cRad, 0)).trigger(); x.modulateDurationBy(dx); - addModulator(y = new SinLFO(cRad, ydMax - cRad, 0)).trigger(); y.modulateDurationBy(dy); - addModulator(z = new SinLFO(cRad, zdMax - cRad, 0)).trigger(); z.modulateDurationBy(dz); + addModulator(x = new SinLFO(cRad, mMax.x - cRad, 0)).trigger(); x.modulateDurationBy(dx); + 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"} ); } - void StartRun(double deltaMs) { cRad = xdMax*pSize.Val()/6; } + void StartRun(double deltaMs) { cRad = mMax.x*pSize.Val()/6; } color CalcPoint(xyz p) { v.set(x.getValuef(), y.getValuef(), z.getValuef()); switch(pChoose.Cur()) { - case 0: vMir.set(xyzdMax); vMir.subtract(p); + case 0: vMir.set(mMax); vMir.subtract(p); return color(0,0,c1c(1 - min(v.distance(p), v.distance(vMir))*.5/cRad)); // balls case 1: return color(0,0,c1c(1 - v.distance(p)*.5/cRad)); // ball - case 2: vMir.set(xdMax/2,0,zdMax/2); + case 2: vMir.set(mMax.x/2,0,mMax.z/2); return color(0,0,c1c(1 - CalcCone(p,v,vMir) * max(.02,.45-pSize.Val()))); // spot } return color(0,0,0); @@ -109,17 +109,17 @@ public class Noise extends DPat color CalcPoint(xyz P) { color c = 0; - P.RotateZ(xyzMid, zSin, zCos); + P.RotateZ(mCtr, zSin, zCos); - if (iSymm == XSym && P.x > xdMax/2) P.x = xdMax-P.x; - if (iSymm == YSym && P.y > ydMax/2) P.y = ydMax-P.y; + 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,xyzMid)/n.xz) + 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; @@ -133,11 +133,29 @@ 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; DParam pAmp, pRad; DParam pRotX, pRotY, pRotZ; float t,amp; + 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(), @@ -157,11 +175,10 @@ public class Play extends DPat pRotZ = addParam("RotZ", .5); pAmp = addParam("Amp" , .2); pRad = addParam("Rad" , .1 ); - pTempoMult = addPick ("TMult" , 5 , 6 , new String[] {"1x", "2x", "4x", "8x", "16x", "Rand" } ); - pTimePattern= addPick ("TPat" , 5 , 6 , new String[] {"Bounce", "Sin", "Roll", "Quant", "Accel", "Rand" } ); - pShape = addPick ("Shape" , 4 , 10 , new String[] {"Line", "Tap", "V", "RandV", "Pyramid", - "Wings", "W2", "Sphere", "Cone", "Noise" } ); - pForm = addPick ("Form" , 0 , 3 , new String[] {"Bar", "Volume", "Fade" } ); + 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"} ); } void StartRun(double deltaMs) { @@ -173,12 +190,12 @@ public class Play extends DPat TCos .set(cos(Theta.x), cos(Theta.y), cos(Theta.z)); 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 == 5) nTPat = CurRandTPat ; + int nTPat = pTimePattern.Cur(); if (nTPat == 7) nTPat = CurRandTPat ; switch (nTempo) { case 0: t = t; break; @@ -188,61 +205,83 @@ public class Play extends DPat case 4: t = (t*16.)%1.; break; } - if (t (pRad.getValuef()+.1)*150?1:0)) ); // sphere - case 8: V.set(cMid); return color(0,0,c1c(1 - CalcCone(Px,V,xyzMid) * 0.02 > .5?1:0)); // cone - case 9: - - - case 10: 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 - default: return color(0,0,0); - } + case 0: V.set(Pn.x, yt , Pn.z); break; // bouncing line + case 1: V.set(Pn.x, map(cos(PI*t * Pn.x),-1,1,0,1) , Pn.z); break; // top tap + case 2: V.set(Pn.x, amp*map(Pn.x<.5?Pn.x:1-Pn.x,0,.5 ,0,t-.5)+.5, Pn.z); break; // V shape + case 3: V.set(Pn.x, Pn.x < cMidNorm.x ? map(Pn.x,0,cMidNorm.x, .5,yt) : + map(Pn.x,cMidNorm.x,1, yt,.5), Pn.z); break; // Random V shape + + case 4: V.set(Pn.x, .5*(Pn.x < cMidNorm.x ? map(Pn.x,0,cMidNorm.x, .5,yt) : + map(Pn.x,cMidNorm.x,1, yt,.5)) + + .5*(Pn.z < cMidNorm.z ? map(Pn.z,0,cMidNorm.z, .5,yt) : + map(Pn.z,cMidNorm.z,1, yt,.5)), Pn.z); break; // Random Pyramid shape + + case 5: V.set(Pn.x, amp*map((Pn.x-.5)*(Pn.x-.5),0,.25,0,t-.5)+.5, Pn.z); break; // wings + case 6: V.set(Pn.x, amp*map((mp -.5)*(mp -.5),0,.25,0,t-.5)+.5, Pn.z); break; // wings + + case 7: return color(0,0, min( + distToSeg(Px.x, Px.y, a1.getX(70),a1.getY(70), mCtr.x, mCtr.y), + distToSeg(Px.x, Px.y, a2.getX(40),a2.getY(40), mCtr.x, mCtr.y)) .5?1:0)); // cone + + case 11: 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 + + default: return color(0,0,0); + } switch (pForm.Cur()) { - case 0: return color(0,0,c1c(1 - V.distance(Pn)/pRad.getValuef() > .5?1:0)); + 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)/pRad.getValuef())); + case 2: return color(0,0,c1c(1 - V.distance(Pn)/rad)); default: return color(0,0,c1c(Pn.y < V.y ?1:0)); } diff --git a/DanUtil.pde b/DanUtil.pde index c098524..7b0c17d 100644 --- a/DanUtil.pde +++ b/DanUtil.pde @@ -1,10 +1,27 @@ //---------------------------------------------------------------------------------------------------------------------------------- -float xdMax,ydMax,zdMax; +xyz mMax, mCtr, mHalf; int NumApcRows = 5, NumApcCols = 8; DGlobals DG = new DGlobals(); -boolean btwn (int a,int b,int c) { return a >= b && a <= c; } -boolean btwn (double a,double b,double c) { return a >= b && a <= c; } +boolean btwn (int a,int b,int c) { return a >= b && a <= c; } +boolean btwn (double a,double b,double c) { return a >= b && a <= c; } +float interp (float a, float b, float c) { return (1-a)*b + a*c; } +float randctr (float a) { return random(a) - a*.5; } +float min (float a, float b, float c, float d) { return min(min(a,b),min(c,d)); } + +float distToSeg (float x, float y, float x1, float y1, float x2, float y2) { + float A = x - x1, B = y - y1, C = x2 - x1, D = y2 - y1; + float dot = A * C + B * D, len_sq = C * C + D * D; + float xx, yy,param = dot / len_sq; + + if (param < 0 || (x1 == x2 && y1 == y2)) { xx = x1; yy = y1; } + else if (param > 1) { xx = x2; yy = y2; } + else { xx = x1 + param * C; + yy = y1 + param * D; } + float dx = x - xx, dy = y - yy; + return sqrt(dx * dx + dy * dy); +} + public class Pick { int NumPicks, Default , CurRow , CurCol , @@ -51,19 +68,22 @@ public class DParam extends BasicParameter { 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(xyz p ) {set(p); } xyz(float _x,float _y,float _z) {x=_x ; y=_y ; z=_z ;} void set(Point p ) {x=p.fx ; y=p.fy; z=p.fz;} void set(xyz p ) {x=p.x ; y=p.y ; z=p.z ;} void set(float _x,float _y,float _z) {x=_x ; y=_y ; z=_z ;} - void zoomX (float zx) {x = x*zx - xdMax*(zx-1)/2; } - void zoomY (float zy) {y = y*zy - ydMax*(zy-1)/2; } + void zoomX (float zx) {x = x*zx - mMax.x*(zx-1)/2; } + void zoomY (float zy) {y = y*zy - mMax.y*(zy-1)/2; } float distance(xyz b) {return dist(x,y,z,b.x,b.y,b.z); } + float distance(float _x, float _y) {return dist(x,y,_x,_y); } float dot (xyz b) {return x*b.x + y*b.y + z*b.z; } void add (xyz b) {x += b.x; y += b.y; z += b.z; } void add (float b) {x += b ; y += b ; z += b ; } void subtract(xyz b) {x -= b.x; y -= b.y; z -= b.z; } + void scale (float b) {x *= b ; y *= b ; z *= b ; } void RotateZ (xyz o, float nSin, float nCos) { float nX = nCos*(x-o.x) - nSin*(y-o.y) + o.x; @@ -83,11 +103,8 @@ public class xyz { float x,y,z; z = nZ; x = nX; } - void setRand () { x = random(xdMax); y = random(ydMax); z = random(zdMax); } - void setNorm () { x /= xdMax; y /= ydMax; z /= zdMax; } - - float interp (float a, float b, float c) { return (1-a)*b + a*c; } - + void setRand () { x = random(mMax.x); y = random(mMax.y); z = random(mMax.z); } + void setNorm () { x /= mMax.x; y /= mMax.y; z /= mMax.z; } void interpolate(float i, xyz d) { x = interp(i,x,d.x); y = interp(i,y,d.y); z = interp(i,z,d.z); } } //---------------------------------------------------------------------------------------------------------------------------------- @@ -166,7 +183,7 @@ public class DGlobals { int row = note.getPitch(), col = note.getChannel(); for (int i=0; i f) return; } - if (pJog.b) { float tRamp = (lx.tempo.rampf() % .25); - if (tRamp < LastJog) - xyzJog.set(random(xdMax*.2)-.1, - random(ydMax*.2)-.1, - random(zdMax*.2)-.1); + if (tRamp < LastJog) xyzJog.set(randctr(mMax.x*.2), randctr(mMax.y*.2), randctr(mMax.z*.2)); LastJog = tRamp; } for (Point p : model.points) { nPoint++; P.set(p); + P.subtract(modmin); if (pJog.b) P.add(xyzJog); - if (DG._Spark () > 0) P.y += DG._Spark () * (noise(P.x,P.y+NoiseMove/30 ,P.z)*ydMax - ydMax/2.); - if (DG._Wiggle() > 0) P.y += DG._Wiggle() * (noise(P.x/(xdMax*.3)-NoiseMove/1500.) - .5) * (ydMax/2.); + if (DG._Spark () > 0) P.y += DG._Spark () * (noise(P.x,P.y+NoiseMove/30 ,P.z)*mMax.y - mMax.y/2.); + if (DG._Wiggle() > 0) P.y += DG._Wiggle() * (noise(P.x/(mMax.x*.3)-NoiseMove/1500.) - .5) * (mMax.y/2.); - color cOld = colors[p.index]; pSave.set(P); - color cNew = CalcPoint(P); - - if (pXsym.b) { P.set(pSave); tP.set(xdMax-P.x,P.y,P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } - if (pYsym.b) { P.set(pSave); tP.set(P.x,ydMax-P.y,P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } - if (pZsym.b) { P.set(pSave); tP.set(P.x,P.y,zdMax-P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } + color cNew, cOld = colors[p.index]; + { tP.set(P); cNew = CalcPoint(tP); } + if (pXsym.b) { tP.set(mMax.x-P.x,P.y,P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } + if (pYsym.b) { tP.set(P.x,mMax.y-P.y,P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } + if (pRsym.b) { tP.set(mMax.x-P.x,mMax.y-P.y,mMax.z-P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } + if (pXdup.b) { tP.set((P.x+mMax.x*.5)%mMax.x,P.y,P.z); cNew = blendColor(cNew, CalcPoint(tP), ADD); } float b = brightness(cNew)/100.; - if (pSharp.Val()>0) b = b < .5 ? pow(b,fSharp) : 1-pow(1-b,fSharp); if (DG._Trails()>0 && fQuant == 0) b = max(b, (float) (brightness(cOld)/100. - (1-DG._Trails()) * deltaMs/200.)); @@ -285,6 +296,9 @@ public class DPat extends SCPattern saturation(cNew) + 100*(fSaturate*2-1), 100 * b * DG._Dim() ); + +// colors[p.index] = color(0,0, p.fx >= modmin.x && p.fy >= modmin.y && p.fz >= modmin.z && +// p.fx <= modmin.x+mMax.x && p.fy <= modmin.y+mMax.y && p.fz <= modmin.z+mMax.z ? 100 : 0); } } }