More DPat Fixes
[SugarCubes.git] / DanHorwitz.pde
1 //----------------------------------------------------------------------------------------------------------------------------------
2 public class Pong extends DPat {
3 SinLFO x,y,z,dx,dy,dz;
4 float cRad; _DhP pSize;
5 Pick pChoose;
6
7 Pong(GLucose glucose) {
8 super(glucose);
9 cRad = xdMax/15;
10 addModulator(dx = new SinLFO(6000, 500, 30000 )).trigger();
11 addModulator(dy = new SinLFO(3000, 500, 22472 )).trigger();
12 addModulator(dz = new SinLFO(1000, 500, 18420 )).trigger();
13 addModulator(x = new SinLFO(cRad, xdMax - cRad, 0)).trigger(); x.modulateDurationBy(dx);
14 addModulator(y = new SinLFO(cRad, ydMax - cRad, 0)).trigger(); y.modulateDurationBy(dy);
15 addModulator(z = new SinLFO(cRad, zdMax - cRad, 0)).trigger(); z.modulateDurationBy(dz);
16 pSize = addParam ("Size" , 0.4 );
17 pChoose = addPick ("Animiation" , 0 , 3, new String[] {"Pong", "Ball", "Cone"} );
18 }
19
20 void StartRun(double deltaMs) { cRad = xdMax*pSize.Val()/6; }
21 color CalcPoint(xyz p) {
22 xyz v = new xyz(x.getValuef(), y.getValuef(), z.getValuef());
23 switch(pChoose.Cur()) {
24 case 0: return color(0,0,c1c(1 - min(v.distance(p), v.distance(xyzdMax.minus(p)))*.5/cRad)); // balls
25 case 1: return color(0,0,c1c(1 - v.distance(p)*.5/cRad)); // ball
26 case 2: return color(0,0,c1c(1 - CalcCone(p,v,new xyz(xdMax/2,0,zdMax/2)) * max(.02,.45-pSize.Val()))); // spot
27 }
28 return color(0,0,0);
29 }
30 }
31 //----------------------------------------------------------------------------------------------------------------------------------
32 public class NDat {
33 float xz, yz, zz, hue, sat, speed, angle, den;
34 float xoff,yoff,zoff;
35 NDat (float _hue, float _sat, float _xz, float _yz, float _zz, float _den, float _speed, float _angle) {
36 hue=_hue; sat=_sat; xz=_xz; yz=_yz; zz =_zz; den=_den; speed=_speed; angle=_angle;
37 xoff = random(100e3); yoff = random(100e3); zoff = random(100e3);
38 }
39 }
40
41 public class Noise extends DPat
42 {
43 int CurAnim = -1, numAnims = 6;
44 float zTime = random(10000), zTheta=0;
45 float rtime = 0, ttime = 0, transAdd=0;
46 int XSym=1,YSym=2,RadSym=3;
47 int iSymm;
48 ArrayList noises = new ArrayList();
49 _DhP pSpeed , pDensity, pRotZ;
50 Pick pChoose, pSymm;
51
52 Noise(GLucose glucose) {
53 super(glucose);
54 pRotZ = addParam("RotZ" , .5 ); pSpeed = addParam("Fast", .55);
55 pDensity= addParam("Dens" , .5);
56 pSymm = addPick("Symmetry" , 0, 4, new String[] {"None", "X", "Y", "Radial"} );
57 pChoose = addPick("Animation", 1, 6, new String[] {"Drip", "Cloud", "Rain", "Fire", "Machine", "Spark"} );
58 }
59
60 void StartRun(double deltaMs) {
61 zTime += deltaMs*(pSpeed.Val()-.5)*.002 ;
62 zTheta += deltaMs*(pRotZ .Val()-.5)*.01 ;
63 rtime += deltaMs;
64 iSymm = pSymm.Cur();
65 transAdd = 1*(1 - constrain(rtime - ttime,0,1000)/1000);
66
67 if (pChoose.Cur() != CurAnim) {
68 noises.clear(); CurAnim = pChoose.Cur(); ttime = rtime;
69 switch(CurAnim) {
70 // hue sat xz yz zz den mph angle
71 case 0: noises.add(new NDat(0 ,0 ,75 ,75 ,150,45 ,3 ,0 )); pSharp.Set(1 ); break; // drip
72 case 1: noises.add(new NDat(0 ,0 ,100,100,200,45 ,3 ,180)); pSharp.Set(0 ); break; // clouds
73 case 2: noises.add(new NDat(0 ,0 ,2 ,400,2 ,20 ,3 ,0 )); pSharp.Set(.5); break; // rain
74 case 3: noises.add(new NDat(40 ,1 ,100,100,200,10 ,1 ,180));
75 noises.add(new NDat(0 ,1 ,100,100,200,10 ,5 ,180)); pSharp.Set(0 ); break; // fire 1
76 case 4: noises.add(new NDat(0 ,1 ,40 ,40 ,40 ,15 ,2.5,180));
77 noises.add(new NDat(20 ,1 ,40 ,40 ,40 ,15 ,4 ,0 ));
78 noises.add(new NDat(40 ,1 ,40 ,40 ,40 ,15 ,2 ,90 ));
79 noises.add(new NDat(60 ,1 ,40 ,40 ,40 ,15 ,3 ,-90)); pSharp.Set(.5); break; // machine
80 case 5: noises.add(new NDat(0 ,1 ,400,100,2 ,15 ,3 ,90 ));
81 noises.add(new NDat(20 ,1 ,400,100,2 ,15 ,2.5,0 ));
82 noises.add(new NDat(40 ,1 ,100,100,2 ,15 ,2 ,180));
83 noises.add(new NDat(60 ,1 ,100,100,2 ,15 ,1.5,270)); pSharp.Set(.5); break; // spark
84 }
85 }
86
87 }
88
89 color CalcPoint(xyz P) {
90 color c = 0;
91 xyz v = P.RotateZ(xyzMid,zTheta);
92 if (iSymm == XSym && v.x > xdMax/2) v.x = xdMax-v.x;
93 if (iSymm == YSym && v.y > ydMax/2) v.y = ydMax-v.y;
94
95 for (int i=0;i<noises.size(); i++) {
96 NDat n = (NDat) noises.get(i);
97 float zx = zTime * n.speed * sin(radians(n.angle)),
98 zy = zTime * n.speed * cos(radians(n.angle));
99
100 float b = (iSymm==RadSym ? noise(zTime*n.speed+n.xoff-Dist(v,xyzMid)/n.xz)
101 : noise(v.x/n.xz+zx+n.xoff,v.y/n.yz+zy+n.yoff,v.z/n.zz+n.zoff))
102 *1.8;
103
104 b += n.den/100 -.4 + pDensity.Val() -1;
105 b += transAdd;
106 c = blendColor(c,color(n.hue,100*n.sat,c1c(b)),ADD);
107 }
108 return c;
109 }
110 }
111 //----------------------------------------------------------------------------------------------------------------------------------
112 public class Play extends DPat
113 {
114 int nBeats = 0;
115 _DhP pAmp, pRad;
116 _DhP pRotX, pRotY, pRotZ;
117 xyz Theta = new xyz();
118 xyz TSin = new xyz();
119 xyz TCos = new xyz();
120
121 Pick pTimePattern, pTempoMult, pShape, pForm;
122 int RandCube;
123
124 Play(GLucose glucose) {
125 super(glucose);
126 pRotX = addParam("RotX", .5);
127 pRotY = addParam("RotY", .5);
128 pRotZ = addParam("RotZ", .5);
129 pAmp = addParam("Amp" , .2);
130 pRad = addParam("Rad" , .1 );
131 pTempoMult = addPick ("TMult" , 0 , 6 , new String[] {"1x", "2x", "4x", "8x", "16x", "Rand" } );
132 pTimePattern= addPick ("TPat" , 0 , 5 , new String[] {"Bounce", "?", "Roll", "Quant", "Accel" } );
133 pShape = addPick ("Shape" , 0 , 10 , new String[] {"Line", "Tap", "V", "RandV", "Pyramid",
134 "Wings", "W2", "Sphere", "Cone", "Noise" } );
135 pForm = addPick ("Form" , 0 , 3 , new String[] {"Bar", "Volume", "Fade" } );
136 }
137
138 float t,a;
139 xyz cPrev = new xyz(), cCur = new xyz(), cMid = new xyz(), cMidNorm;
140 float LastBeat=3, LastMeasure=3;
141 int CurRandTempo = 1;
142
143 void StartRun(double deltaMs) {
144 t = lx.tempo.rampf();
145 a = pAmp.Val();
146
147 Theta .set(pRotX.Val()*PI*2, pRotY.Val()*PI*2, pRotZ.Val()*PI*2);
148 TSin .set(sin(Theta.x), sin(Theta.y), sin(Theta.z));
149 TCos .set(cos(Theta.x), cos(Theta.y), cos(Theta.z));
150
151 if (t<LastMeasure) { CurRandTempo = int(random(4)); } LastMeasure = t;
152
153 switch (pTempoMult.Cur()) {
154 case 0: t = t; break;
155 case 1: t = (t*2. )%1.; break;
156 case 2: t = (t*4. )%1.; break;
157 case 3: t = (t*8. )%1.; break;
158 case 4: t = (t*16.)%1.; break;
159 case 5: t = (t*pow(2,CurRandTempo))%1.; break;
160 }
161
162 if (t<LastBeat) { cPrev = cCur; cCur = cCur.setRand(); } LastBeat = t;
163
164 switch (pTimePattern.Cur()) {
165 case 0: t = sin(PI*t); break;
166 case 1: t = norm(sin(2*PI*(t+PI/2)),-1,1); break;
167 case 2: t = t; break;
168 case 3: t = constrain(int(t*8)/7.,0,1); break;
169 case 4: t = t*t*t; break;
170 }
171
172
173 cMid = cPrev.interpolate(t,cCur);
174 cMidNorm = cMid.setNorm();
175 }
176
177 color CalcPoint(xyz Px) {
178 xyz V = new xyz();
179 xyz P = Px.setNorm();
180 P.RotateXYZ(xyzHalf, Theta, TSin, TCos);
181
182 float mp = min(P.x, P.z);
183 float yt = map(t,0,1,.5-a/2,.5+a/2);
184
185 switch (pShape.Cur()) {
186 case 0: V.set(P.x, yt , P.z); break; // bouncing line
187 case 1: V.set(P.x, map(cos(PI*t * P.x),-1,1,0,1) , P.z); break; // top tap
188 case 2: V.set(P.x, a*map(P.x<.5?P.x:1-P.x,0,.5 ,0,t-.5)+.5, P.z); break; // V shape
189 case 3: V.set(P.x, P.x < cMidNorm.x ? map(P.x,0,cMidNorm.x, .5,yt) :
190 map(P.x,cMidNorm.x,1, yt,.5), P.z); break; // Random V shape
191
192 case 4: V.set(P.x, .5*(P.x < cMidNorm.x ? map(P.x,0,cMidNorm.x, .5,yt) :
193 map(P.x,cMidNorm.x,1, yt,.5)) +
194 .5*(P.z < cMidNorm.z ? map(P.z,0,cMidNorm.z, .5,yt) :
195 map(P.z,cMidNorm.z,1, yt,.5)), P.z); break; // Random Pyramid shape
196
197 case 5: V.set(P.x, a*map((P.x-.5)*(P.x-.5),0,.25,0,t-.5)+.5, P.z); break; // wings
198 case 6: V.set(P.x, a*map((mp -.5)*(mp -.5),0,.25,0,t-.5)+.5, P.z); break; // wings
199
200 case 7: V.set(cMid.x,cMid.y,cMid.z);
201 return color(0,0,c1c(1 - (V.distance(Px) > (pRad.getValuef()+.1)*150?1:0)) ); // sphere
202
203 case 8: V.set(cMid.x,cMid.y,cMid.z);
204 return color(0,0,c1c(1 - CalcCone(Px,V,xyzMid) * 0.02 > .5?1:0)); // cone
205
206 case 9: return color(100 + noise(P.x,P.y,P.z + (NoiseMove+50000)/1000.)*200,
207 85,c1c(P.y < noise(P.x + NoiseMove/2000.,P.z)*(1+a)-a/2.-.1 ? 1 : 0)); //
208 }
209
210
211 switch (pForm.Cur()) {
212 case 0: return color(0,0,c1c(1 - V.distance(P)/pRad.getValuef() > .5?1:0));
213 case 1: return color(0,0,c1c(P.y < V.y ?1:0));
214 case 2: return color(0,0,c1c(1 - V.distance(P)/pRad.getValuef()));
215
216 default: return color(0,0,c1c(P.y < V.y ?1:0));
217 }
218 }
219 }
220 //----------------------------------------------------------------------------------------------------------------------------------