}\r
//----------------------------------------------------------------------------------------------------------------------------------\r
public class NDat {\r
- float xz, yz, zz, hue, sat, speed, angle, den;\r
- float xoff,yoff,zoff;\r
- NDat (float _hue, float _sat, float _xz, float _yz, float _zz, float _den, float _speed, float _angle) {\r
+ float xz, yz, zz, hue, sat, speed, angle, den;\r
+ float xoff,yoff,zoff;\r
+ float sinAngle, cosAngle;\r
+ boolean isActive;\r
+ NDat () { isActive=false; }\r
+ boolean Active() { return isActive; }\r
+ void set (float _hue, float _sat, float _xz, float _yz, float _zz, float _den, float _speed, float _angle) {\r
+ isActive = true;\r
hue=_hue; sat=_sat; xz=_xz; yz=_yz; zz =_zz; den=_den; speed=_speed; angle=_angle;\r
xoff = random(100e3); yoff = random(100e3); zoff = random(100e3);\r
}\r
\r
public class Noise extends DPat\r
{\r
- int CurAnim = -1, numAnims = 6;\r
- float zTime = random(10000), zTheta=0;\r
- float rtime = 0, ttime = 0, transAdd=0;\r
+ int CurAnim, iSymm;\r
int XSym=1,YSym=2,RadSym=3;\r
- int iSymm;\r
- ArrayList noises = new ArrayList();\r
+ float zTime = random(10000), zTheta=0, zSin, zCos;\r
+ float rtime = 0, ttime = 0, transAdd=0;\r
_DhP pSpeed , pDensity, pRotZ;\r
Pick pChoose, pSymm;\r
+ int _ND = 4;\r
+ NDat N[] = new NDat[_ND];\r
\r
Noise(GLucose glucose) {\r
super(glucose);\r
pDensity= addParam("Dens" , .5);\r
pSymm = addPick("Symmetry" , 0, 4, new String[] {"None", "X", "Y", "Radial"} );\r
pChoose = addPick("Animation", 1, 6, new String[] {"Drip", "Cloud", "Rain", "Fire", "Machine", "Spark"} );\r
+ for (int i=0; i<_ND; i++) N[i] = new NDat();\r
}\r
\r
void StartRun(double deltaMs) {\r
rtime += deltaMs;\r
iSymm = pSymm.Cur();\r
transAdd = 1*(1 - constrain(rtime - ttime,0,1000)/1000);\r
+ zSin = sin(zTheta);\r
+ zCos = cos(zTheta);\r
\r
if (pChoose.Cur() != CurAnim) {\r
- noises.clear(); CurAnim = pChoose.Cur(); ttime = rtime;\r
+ CurAnim = pChoose.Cur(); ttime = rtime;\r
+ pRotZ .reset(); zTheta = 0;\r
+ pDensity .reset(); pSpeed .reset(); \r
+ for (int i=0; i<_ND; i++) { N[i].isActive = false; }\r
+ \r
switch(CurAnim) {\r
// hue sat xz yz zz den mph angle\r
- case 0: noises.add(new NDat(0 ,0 ,75 ,75 ,150,45 ,3 ,0 )); pSharp.Set(1 ); break; // drip\r
- case 1: noises.add(new NDat(0 ,0 ,100,100,200,45 ,3 ,180)); pSharp.Set(0 ); break; // clouds\r
- case 2: noises.add(new NDat(0 ,0 ,2 ,400,2 ,20 ,3 ,0 )); pSharp.Set(.5); break; // rain\r
- case 3: noises.add(new NDat(40 ,1 ,100,100,200,10 ,1 ,180)); \r
- noises.add(new NDat(0 ,1 ,100,100,200,10 ,5 ,180)); pSharp.Set(0 ); break; // fire 1\r
- case 4: noises.add(new NDat(0 ,1 ,40 ,40 ,40 ,15 ,2.5,180));\r
- noises.add(new NDat(20 ,1 ,40 ,40 ,40 ,15 ,4 ,0 ));\r
- noises.add(new NDat(40 ,1 ,40 ,40 ,40 ,15 ,2 ,90 ));\r
- noises.add(new NDat(60 ,1 ,40 ,40 ,40 ,15 ,3 ,-90)); pSharp.Set(.5); break; // machine\r
- case 5: noises.add(new NDat(0 ,1 ,400,100,2 ,15 ,3 ,90 ));\r
- noises.add(new NDat(20 ,1 ,400,100,2 ,15 ,2.5,0 ));\r
- noises.add(new NDat(40 ,1 ,100,100,2 ,15 ,2 ,180));\r
- noises.add(new NDat(60 ,1 ,100,100,2 ,15 ,1.5,270)); pSharp.Set(.5); break; // spark\r
+ case 0: N[0].set(0 ,0 ,75 ,75 ,150,45 ,3 ,0 ); pSharp.Set(1 ); break; // drip\r
+ case 1: N[0].set(0 ,0 ,100,100,200,45 ,3 ,180); pSharp.Set(0 ); break; // clouds\r
+ case 2: N[0].set(0 ,0 ,2 ,400,2 ,20 ,3 ,0 ); pSharp.Set(.5); break; // rain\r
+ case 3: N[0].set(40 ,1 ,100,100,200,10 ,1 ,180); \r
+ N[1].set(0 ,1 ,100,100,200,10 ,5 ,180); pSharp.Set(0 ); break; // fire 1\r
+ case 4: N[0].set(0 ,1 ,40 ,40 ,40 ,15 ,2.5,180);\r
+ N[1].set(20 ,1 ,40 ,40 ,40 ,15 ,4 ,0 );\r
+ N[2].set(40 ,1 ,40 ,40 ,40 ,15 ,2 ,90 );\r
+ N[3].set(60 ,1 ,40 ,40 ,40 ,15 ,3 ,-90); pSharp.Set(.5); break; // machine\r
+ case 5: N[0].set(0 ,1 ,400,100,2 ,15 ,3 ,90 );\r
+ N[1].set(20 ,1 ,400,100,2 ,15 ,2.5,0 );\r
+ N[2].set(40 ,1 ,100,100,2 ,15 ,2 ,180);\r
+ N[3].set(60 ,1 ,100,100,2 ,15 ,1.5,270); pSharp.Set(.5); break; // spark\r
}\r
- }\r
\r
+ DG.UpdateLights();\r
+ }\r
+ \r
+ for (int i=0; i<_ND; i++) if (N[i].Active()) {\r
+ N[i].sinAngle = sin(radians(N[i].angle));\r
+ N[i].cosAngle = cos(radians(N[i].angle));\r
+ }\r
}\r
\r
color CalcPoint(xyz P) {\r
color c = 0;\r
- xyz v = P.RotateZ(xyzMid,zTheta);\r
- if (iSymm == XSym && v.x > xdMax/2) v.x = xdMax-v.x;\r
- if (iSymm == YSym && v.y > ydMax/2) v.y = ydMax-v.y;\r
-\r
- for (int i=0;i<noises.size(); i++) {\r
- NDat n = (NDat) noises.get(i);\r
- float zx = zTime * n.speed * sin(radians(n.angle)),\r
- zy = zTime * n.speed * cos(radians(n.angle));\r
+ P.RotateZ(xyzMid, zSin, zCos);\r
+ \r
+ if (iSymm == XSym && P.x > xdMax/2) P.x = xdMax-P.x;\r
+ if (iSymm == YSym && P.y > ydMax/2) P.y = ydMax-P.y;\r
+\r
+ for (int i=0;i<_ND; i++) if (N[i].Active()) {\r
+ NDat n = N[i];\r
+ float zx = zTime * n.speed * n.sinAngle,\r
+ zy = zTime * n.speed * n.cosAngle;\r
\r
- float b = (iSymm==RadSym ? noise(zTime*n.speed+n.xoff-Dist(v,xyzMid)/n.xz)\r
- : noise(v.x/n.xz+zx+n.xoff,v.y/n.yz+zy+n.yoff,v.z/n.zz+n.zoff))\r
+ float b = (iSymm==RadSym ? noise(zTime*n.speed+n.xoff-Dist(P,xyzMid)/n.xz)\r
+ : noise(P.x/n.xz+zx+n.xoff,P.y/n.yz+zy+n.yoff,P.z/n.zz+n.zoff))\r
*1.8;\r
\r
b += n.den/100 -.4 + pDensity.Val() -1;\r
pAmp = addParam("Amp" , .2);\r
pRad = addParam("Rad" , .1 );\r
pTempoMult = addPick ("TMult" , 0 , 6 , new String[] {"1x", "2x", "4x", "8x", "16x", "Rand" } );\r
- pTimePattern= addPick ("TPat" , 0 , 5 , new String[] {"Bounce", "?", "Roll", "Quant", "Accel" } );\r
+ pTimePattern= addPick ("TPat" , 0 , 5 , new String[] {"Bounce", "Sin", "Roll", "Quant", "Accel" } );\r
pShape = addPick ("Shape" , 0 , 10 , new String[] {"Line", "Tap", "V", "RandV", "Pyramid",\r
"Wings", "W2", "Sphere", "Cone", "Noise" } );\r
pForm = addPick ("Form" , 0 , 3 , new String[] {"Bar", "Volume", "Fade" } );\r
}\r
\r
color CalcPoint(xyz Px) {\r
- xyz V = new xyz();\r
- xyz P = Px.setNorm();\r
- P.RotateXYZ(xyzHalf, Theta, TSin, TCos);\r
+ xyz V = new xyz();\r
+ xyz P = Px.setNorm();\r
+ if (Theta.x != 0) P.RotateX(xyzHalf, TSin.x, TCos.x);\r
+ if (Theta.y != 0) P.RotateY(xyzHalf, TSin.y, TCos.y);\r
+ if (Theta.z != 0) P.RotateZ(xyzHalf, TSin.z, TCos.z);\r
\r
float mp = min(P.x, P.z);\r
float yt = map(t,0,1,.5-a/2,.5+a/2);\r
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(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 ); }
-
+ 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 ); }
+ boolean isZero () {return x==0 && y==0 && z==0; }
+
+ void RotateZ (xyz o, float nSin, float nCos) {
+ float nX = nCos*(x-o.x) - nSin*(y-o.y) + o.x;
+ float nY = nSin*(x-o.x) + nCos*(y-o.y) + o.y;
+ x = nX; y = nY;
+ }
- void RotateXYZ (xyz o, xyz t, xyz tsin, xyz tcos) {
- { x -= o.x; y -= o.y; z -= o.z; }
- if (t.x != 0) { y = y*tcos.x - z*tsin.x; z = y*tsin.x + z*tcos.x; }
- if (t.y != 0) { z = z*tcos.y - x*tsin.y; x = z*tsin.y + x*tcos.y; }
- if (t.z != 0) { x = x*tcos.z - y*tsin.z; y = x*tsin.z + y*tcos.z; }
- { x += o.x; y += o.y; z += o.z; }
+ void RotateX (xyz o, float nSin, float nCos) {
+ float nY = nCos*(y-o.y) - nSin*(z-o.z) + o.y;
+ float nZ = nSin*(y-o.y) + nCos*(z-o.z) + o.z;
+ y = nY; z = nZ;
+ }
+
+ void RotateY (xyz o, float nSin, float nCos) {
+ float nZ = nCos*(z-o.z) - nSin*(x-o.x) + o.z;
+ float nX = nSin*(z-o.z) + nCos*(x-o.x) + o.x;
+ z = nZ; x = nX;
}
xyz setRand () { return new xyz ( random(xdMax), random(ydMax), random(zdMax)); }
for (MidiInputDevice input : RWMidi.getInputDevices ()) {
if (input.toString().contains("APC")) input.createInput (this);
}
- }
+ }
void SetText()
{
//else { println(cc.getCC() + " " + cc.getChannel() + " " + cc.getValue()); }
}
-
+
void Deactivate (DPat p) { if (p == CurPat) { uiDebugText.setText(""); CurPat = NextPat; } NextPat = null; }
void Activate (DPat p) {
NextPat = CurPat; CurPat = p;