Added TobySegaran.pde with a couple of new patterns
[SugarCubes.git] / TobySegaran.pde
1 class WarmPlasma extends SCPattern {
2 private int pos = 0;
3 private float satu = 100;
4 private float speed = 1;
5 BasicParameter saturationParameter = new BasicParameter("SATU", 1.0);
6 BasicParameter speedParameter = new BasicParameter("SPEED", 0.1);
7
8 public WarmPlasma(GLucose glucose) {
9 super(glucose);
10 addParameter(saturationParameter);
11 addParameter(speedParameter);
12 }
13 public void onParameterChanged(LXParameter parameter) {
14 if (parameter == saturationParameter) {
15 satu = 100*parameter.getValuef();
16 } else if (parameter == speedParameter) {
17 speed = 10*parameter.getValuef();
18 }
19 }
20
21 public void run(int deltaMs) {
22 for (Point p : model.points) {
23 float hv = sin(dist(p.fx + pos, p.fy, 128.0, 128.0) / 8.0)
24 + sin(dist(p.fx, p.fy, 64.0, 64.0) / 8.0)
25 + sin(dist(p.fx, p.fy + pos / 7, 192.0, 64.0) / 7.0)
26 + sin(dist(p.fx, p.fz + pos, 192.0, 100.0) / 8.0);
27 float bv = 100;
28 colors[p.index] = color((hv+2)*25, satu, bv);
29 }
30 pos+=speed;
31 if (pos >= MAX_INT-1) pos=0;
32 }
33 }
34
35 class FireTest extends SCPattern {
36 private float[][] intensity;
37 private float hotspot;
38 private float decay = 0.3;
39 private int xm;
40 private int ym;
41 BasicParameter decayParameter = new BasicParameter("DECAY", 0.3);
42
43 public FireTest(GLucose glucose) {
44 super(glucose);
45 xm = int(model.xMax);
46 ym = int(model.yMax);
47
48 intensity = new float[xm][ym];
49 addParameter(decayParameter);
50 }
51 public void onParameterChanged(LXParameter parameter) {
52 if (parameter == decayParameter) {
53 decay = parameter.getValuef();
54 }
55 }
56 private color flameColor(float level) {
57 if (level<=0) return color(0,0,0);
58 float br=min(100,sqrt(level)*15);
59 return color(level/1.7,100,br);
60 }
61 public void run(int deltaMs) {
62 for (int x=10;x<xm-10;x++) {
63 if (x%50>45 || x%50<5) {
64 intensity[x][ym-1] = random(30,100);
65 } else {
66 intensity[x][ym-1] = random(0,50);
67 }
68 }
69 for (int x=1;x<xm-1;x++) {
70 for (int y=0;y<ym-1;y++) {
71 intensity[x][y] = (intensity[x-1][y+1]+intensity[x][y+1]+intensity[x+1][y+1])/3-decay;
72 }
73 }
74
75 for (Point p : model.points) {
76 int x = (int(p.fx)+int(p.fz))%xm;
77 int y = min(ym-int(p.fy),ym-1);
78 colors[p.index] = flameColor(intensity[x][y]);
79 }
80 }
81 }