minor updates
[SugarCubes.git] / DanHorwitz.pde
1 public class _P extends BasicParameter {
2 _P(String label, double value) { super(label,value); }
3 public void updateValue (double value) { super.updateValue(value); }
4 public float Val () { return getValuef(); }
5 public int Pick (int b) { return int(Val())==1 ? b-1 : int(b*Val()); }
6 }
7
8 float c1c (float a) { return 100*constrain(a,0,1); }
9 float CalcCone (float x1, float y1, float z1, float x2, float y2, float z2) {
10 return degrees( acos ( ( x1*x2 + y1*y2 + z1*z2 ) / (sqrt(x1*x1+y1*y1+z1*z1) * sqrt(x2*x2+y2*y2+z2*z2)) ) );}
11 float xMax,yMax,zMax;
12 float zTime = random(10000);
13 _P pChoose = new _P("ANIM", 0);
14 //----------------------------------------------------------------------------------------------------------------------------------
15 class Pong extends SCPattern {
16 SinLFO x,y,z,dx,dy,dz;
17 float cRad; _P size;
18
19 Pong(GLucose glucose) {
20 super(glucose);
21 xMax = model.xMax; yMax = model.yMax; zMax = model.zMax;
22 cRad = xMax/15;
23 addModulator(dx = new SinLFO(6000, 500, 30000 )).trigger();
24 addModulator(dy = new SinLFO(3000, 500, 22472 )).trigger();
25 addModulator(dz = new SinLFO(1000, 500, 18420 )).trigger();
26 addModulator(x = new SinLFO(cRad, xMax - cRad, 0)).trigger(); x.modulateDurationBy(dx);
27 addModulator(y = new SinLFO(cRad, yMax - cRad, 0)).trigger(); y.modulateDurationBy(dy);
28 addModulator(z = new SinLFO(cRad, zMax - cRad, 0)).trigger(); z.modulateDurationBy(dz);
29 addParameter(pChoose);
30 addParameter(size = new _P("SIZE", 0.4));
31 }
32
33 color Calc(float px, float py, float pz, float vx, float vy, float vz) {
34 switch(pChoose.Pick(3)) {
35 /*spot*/ case 0: return color(0,0,c1c(1 - CalcCone(vx-xMax/2, vy, vz-zMax/2, px-xMax/2, py, pz-zMax/2)*max(.02,.45-size.Val())));
36 /*ball*/ case 1: return color(0,0,c1c(1 - dist(vx,vy,vz,px,py,pz)*.5/cRad));
37 /*ballz*/ default:return color(0,0,c1c(1 - min( dist(vx,vy,vz,px,py,pz),
38 dist(vx,vy,vz,xMax-px,yMax-py,zMax-pz))*.5/cRad));
39 }
40 }
41
42 public void run(int deltaMs) {
43 cRad = xMax*size.Val()/6;
44 for (Point p : model.points) {
45 colors[p.index] = Calc(p.fx, p.fy, p.fz, x.getValuef(), y.getValuef(), z.getValuef());
46 }
47 }
48 }
49 //----------------------------------------------------------------------------------------------------------------------------------
50 class NDat {
51 float xz, yz, zz, hue, sat, speed, dir, den, contrast;
52 float xoff,yoff,zoff;
53 NDat (float _hue, float _sat, float _xz, float _yz, float _zz, float _con, float _den, float _speed, float _dir) {
54 hue=_hue; sat=_sat; xz=_xz; yz=_yz; zz =_zz; contrast=_con; den=_den; speed=_speed; dir=_dir;
55 xoff = random(100e3); yoff = random(100e3); zoff = random(100e3);
56 }
57 }
58
59 class Noise extends SCPattern
60 {
61 int CurAnim = -1 ;
62 ArrayList noises = new ArrayList();
63 _P pSpeed, pMir, pBright, pContrast, pDensity, pDir;
64
65 Noise(GLucose glucose) {
66 super(glucose); addParameter(pChoose );
67 addParameter(pSpeed = new _P("MPH" , .55)); addParameter(pMir = new _P("MIR" , 0 ));
68 addParameter(pBright = new _P("BRTE" , 1 )); addParameter(pDir = new _P("DIR" , 0 ));
69 addParameter(pContrast = new _P("CNTR" , .5)); addParameter(pDensity = new _P("DENS" , .5));
70 }
71
72 public void run(int deltaMs) {
73 zTime += deltaMs*(pSpeed.Val()-.5)*.002;
74 int anim = pChoose.Pick(6);
75 if (anim != CurAnim) {
76 noises.clear(); CurAnim = anim; switch(anim) {
77 //_hue, _sat, _xz, _yz, _zz, _con, _den, _speed, _dir
78 case 0: noises.add(new NDat(0 ,0 ,100,100,200,0 ,40 ,3 ,2)); break; // clouds
79 case 1: noises.add(new NDat(0 ,0 ,75 ,75 ,150,1 ,45 ,3 ,0)); break; // drip
80 case 2: noises.add(new NDat(0 ,0 ,2 ,400,2 ,1 ,40 ,3 ,0)); break; // rain
81 case 3: noises.add(new NDat(40 ,100,100,100,200,0 ,20 ,1 ,2));
82 noises.add(new NDat(0 ,100,100,100,200,0 ,20 ,5 ,2)); break; // fire 1
83 case 4: noises.add(new NDat(0 ,100,40 ,40 ,40 ,.5 ,25 ,2.5 ,2));
84 noises.add(new NDat(20 ,100,40 ,40 ,40 ,.5 ,25 ,4 ,0));
85 noises.add(new NDat(40 ,100,40 ,40 ,40 ,.5 ,25 ,2 ,1));
86 noises.add(new NDat(60 ,100,40 ,40 ,40 ,.5 ,25 ,3 ,3)); break; // machine
87 case 5: noises.add(new NDat(0 ,100,400,100,2 ,1 ,20 ,3 ,2));
88 noises.add(new NDat(20 ,100,400,100,2 ,1 ,20 ,2.5 ,0));
89 noises.add(new NDat(40 ,400,100,100,2 ,1 ,20 ,2 ,1));
90 noises.add(new NDat(60 ,400,100,100,2 ,1 ,20 ,1.5 ,3)); break; // spark
91 default: break;
92 }
93 }
94
95 for (Point p : model.points) {
96 color c = color(0,0,0);
97 int mir = pMir.Pick(5);
98
99 for (int i=0;i<noises.size(); i++) { NDat n = (NDat) noises.get(i);
100 float vx=p.fx, vy=p.fy, vz=p.fz;
101 // if (vx > xMax/2 && (mir == 1 || mir == 3 || mir == 4)) { vx = xMax-vx; }
102 if (vy > yMax/2 && (mir == 2 || mir == 3 || mir == 4)) { vy = yMax-vy; }
103 // if (vz > zMax/2 && ( mir == 4)) { vz = zMax-vz; }
104 float deg = radians(90*(n.dir + pDir.Pick(4)));
105 float zx = zTime * n.speed * sin(deg);
106 float zy = zTime * n.speed * cos(deg);
107 float b = noise(vx/n.xz+zx+n.xoff,vy/n.yz+zy+n.yoff,vz/n.zz+n.zoff)*1.6-.3 + n.den/100 + pDensity.Val() -1;
108 float con = 1/constrain(2-n.contrast - 2*pContrast.Val(),0,1);
109 b = b < .5 ? pow(b,con) : 1-pow(1-b,con);
110 c = blendColor(c,color(n.hue,n.sat,c1c(b * pBright.Val())),ADD);
111 }
112 colors[p.index] = c;
113 }
114 }
115 }
116 //----------------------------------------------------------------------------------------------------------------------------------