Merge branch 'master' of https://github.com/sugarcubes/SugarCubes
[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 // This is very much a work in progress. Trying to get a flame effect.
36 class FireTest extends SCPattern {
37 private float[][] intensity;
38 private float hotspot;
39 private float decay = 0.3;
40 private int xm;
41 private int ym;
42 BasicParameter decayParameter = new BasicParameter("DECAY", 0.3);
43
44 public FireTest(GLucose glucose) {
45 super(glucose);
46 xm = int(model.xMax);
47 ym = int(model.yMax);
48
49 intensity = new float[xm][ym];
50 addParameter(decayParameter);
51 }
52 public void onParameterChanged(LXParameter parameter) {
53 if (parameter == decayParameter) {
54 decay = parameter.getValuef();
55 }
56 }
57 private color flameColor(float level) {
58 if (level<=0) return color(0,0,0);
59 float br=min(100,sqrt(level)*15);
60 return color(level/1.7,100,br);
61 }
62 public void run(int deltaMs) {
63 for (int x=10;x<xm-10;x++) {
64 if (x%50>45 || x%50<5) {
65 intensity[x][ym-1] = random(30,100);
66 } else {
67 intensity[x][ym-1] = random(0,50);
68 }
69 }
70 for (int x=1;x<xm-1;x++) {
71 for (int y=0;y<ym-1;y++) {
72 intensity[x][y] = (intensity[x-1][y+1]+intensity[x][y+1]+intensity[x+1][y+1])/3-decay;
73 }
74 }
75
76 for (Point p : model.points) {
77 int x = (int(p.fx)+int(p.fz))%xm;
78 int y = min(ym-int(p.fy),ym-1);
79 colors[p.index] = flameColor(intensity[x][y]);
80 }
81 }
82 }