Commit | Line | Data |
---|---|---|
4ad0649d TS |
1 | class WarmPlasma extends SCPattern { |
2 | private int pos = 0; | |
3 | private float satu = 100; | |
4 | private float speed = 1; | |
64d16e07 | 5 | private float glitch = 0; |
4ad0649d TS |
6 | BasicParameter saturationParameter = new BasicParameter("SATU", 1.0); |
7 | BasicParameter speedParameter = new BasicParameter("SPEED", 0.1); | |
64d16e07 | 8 | BasicParameter glitchParameter = new BasicParameter("GLITCH", 0.0); |
4ad0649d TS |
9 | |
10 | public WarmPlasma(GLucose glucose) { | |
11 | super(glucose); | |
12 | addParameter(saturationParameter); | |
13 | addParameter(speedParameter); | |
64d16e07 | 14 | addParameter(glitchParameter); |
4ad0649d TS |
15 | } |
16 | public void onParameterChanged(LXParameter parameter) { | |
17 | if (parameter == saturationParameter) { | |
18 | satu = 100*parameter.getValuef(); | |
19 | } else if (parameter == speedParameter) { | |
20 | speed = 10*parameter.getValuef(); | |
64d16e07 TS |
21 | } else if (parameter == glitchParameter) { |
22 | glitch = parameter.getValuef(); | |
4ad0649d TS |
23 | } |
24 | } | |
25 | ||
26 | public void run(int deltaMs) { | |
27 | for (Point p : model.points) { | |
28 | float hv = sin(dist(p.fx + pos, p.fy, 128.0, 128.0) / 8.0) | |
29 | + sin(dist(p.fx, p.fy, 64.0, 64.0) / 8.0) | |
30 | + sin(dist(p.fx, p.fy + pos / 7, 192.0, 64.0) / 7.0) | |
31 | + sin(dist(p.fx, p.fz + pos, 192.0, 100.0) / 8.0); | |
32 | float bv = 100; | |
33 | colors[p.index] = color((hv+2)*25, satu, bv); | |
34 | } | |
64d16e07 TS |
35 | if (random(1.0)<glitch/10) { |
36 | pos=pos-20; | |
37 | } | |
4ad0649d | 38 | pos+=speed; |
64d16e07 | 39 | if (pos >= MAX_INT-1) pos=0; |
4ad0649d TS |
40 | } |
41 | } | |
42 | ||
99c99d34 | 43 | // This is very much a work in progress. Trying to get a flame effect. |
64d16e07 | 44 | class FireEffect extends SCPattern { |
4ad0649d TS |
45 | private float[][] intensity; |
46 | private float hotspot; | |
47 | private float decay = 0.3; | |
48 | private int xm; | |
49 | private int ym; | |
50 | BasicParameter decayParameter = new BasicParameter("DECAY", 0.3); | |
51 | ||
64d16e07 | 52 | public FireEffect(GLucose glucose) { |
4ad0649d TS |
53 | super(glucose); |
54 | xm = int(model.xMax); | |
55 | ym = int(model.yMax); | |
56 | ||
57 | intensity = new float[xm][ym]; | |
58 | addParameter(decayParameter); | |
59 | } | |
60 | public void onParameterChanged(LXParameter parameter) { | |
61 | if (parameter == decayParameter) { | |
62 | decay = parameter.getValuef(); | |
63 | } | |
64 | } | |
65 | private color flameColor(float level) { | |
66 | if (level<=0) return color(0,0,0); | |
67 | float br=min(100,sqrt(level)*15); | |
68 | return color(level/1.7,100,br); | |
69 | } | |
70 | public void run(int deltaMs) { | |
71 | for (int x=10;x<xm-10;x++) { | |
72 | if (x%50>45 || x%50<5) { | |
73 | intensity[x][ym-1] = random(30,100); | |
74 | } else { | |
75 | intensity[x][ym-1] = random(0,50); | |
76 | } | |
77 | } | |
78 | for (int x=1;x<xm-1;x++) { | |
79 | for (int y=0;y<ym-1;y++) { | |
80 | intensity[x][y] = (intensity[x-1][y+1]+intensity[x][y+1]+intensity[x+1][y+1])/3-decay; | |
81 | } | |
82 | } | |
83 | ||
84 | for (Point p : model.points) { | |
64d16e07 TS |
85 | int x = max(0,(int(p.fx)+int(p.fz))%xm); |
86 | int y = constrain(ym-int(p.fy),0,ym-1); | |
4ad0649d TS |
87 | colors[p.index] = flameColor(intensity[x][y]); |
88 | } | |
89 | } | |
90 | } | |
64d16e07 | 91 |