-
Notifications
You must be signed in to change notification settings - Fork 9
/
GranimPattern.pde
236 lines (210 loc) · 3.86 KB
/
GranimPattern.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import java.util.LinkedHashMap;
class Graphic
{
public boolean changed = false;
public int position = 0;
public ArrayList<Integer> graphicBuffer;
Graphic()
{
graphicBuffer = new ArrayList<Integer>();
}
public int width()
{
return graphicBuffer.size();
}
};
class Granim extends Graphic
{
HashMap<String,Graphic> displayList;
Granim()
{
displayList = new HashMap<String,Graphic>();
}
public Graphic addGraphic(String name, Graphic g)
{
while(width()< g.position+1)
{
graphicBuffer.add(color(0,0,0));
}
drawAll();
displayList.put(name , g);
changed =true;
return g;
}
public Graphic getGraphicByName(String name)
{
return displayList.get(name);
}
public void update()
{
for(Graphic g : displayList.values())
{
if(g instanceof Granim)
{
((Granim) g).update();
}
changed = changed || g.changed;
if(changed)
{
while(width()< g.position + g.width())
{
graphicBuffer.add(color(0,0,0));
}
if(g.changed)
{
drawOne(g);
g.changed =false;
}
}
}
changed = false;
}
public void drawOne(Graphic g)
{
graphicBuffer.addAll(g.position,g.graphicBuffer);
}
public void drawAll()
{
}
};
class GranimPattern extends SCPattern
{
HashMap<String,Graphic> displayList;
GranimPattern(GLucose glucose)
{
super(glucose);
displayList = new HashMap<String,Graphic>();
}
public Graphic addGraphic(String name, Graphic g)
{
displayList.put(name,g);
return g;
}
public Graphic getGraphicByName(String name)
{
return displayList.get(name);
}
public void run(int deltaMs)
{
drawToPointList();
}
private Integer[] gbuffer;
public void drawToPointList()
{
for(Graphic g : displayList.values())
{
if(g instanceof Granim)
{
((Granim) g).update();
}
List<Point> drawList = model.points.subList(Math.min(g.position,colors.length-1), Math.min(g.position + g.width(),colors.length-1));
//println("drawlistsize "+drawList.size());
gbuffer = g.graphicBuffer.toArray(new Integer[0]);
for (int i=0; i < drawList.size(); i++)
{
colors[drawList.get(i).index] = gbuffer[i];
}
g.changed = false;
}
}
};
class RedsGraphic extends Graphic
{
RedsGraphic()
{
super();
drawit(10);
}
RedsGraphic(int len)
{
super();
drawit(len);
}
void drawit(int len)
{
for(int i = 0; i < len ;i++)
{
graphicBuffer.add(color(0,255,255));
}
}
};
class RedsGranim extends Granim
{
RedsGranim()
{
super();
addGraphic("myreds", new RedsGraphic(10));
}
RedsGranim(int len)
{
super();
addGraphic("myreds", new RedsGraphic(len));
}
public float count = 0.0;
public void update()
{
Graphic g=getGraphicByName("myreds");
g.position = Math.round(sin(count)*20)+100;
count+= 0.1;
if(count>Math.PI*2)
{
count=0;
}
super.update();
}
};
class RandomsGranim extends Granim
{
private int _len =0 ;
RandomsGranim()
{
super();
_len =100;
addGraphic("myrandoms", makeGraphic(_len));
}
RandomsGranim(int len)
{
super();
_len=len;
addGraphic("myrandoms", makeGraphic(len));
}
int colorLid=0;
public Graphic makeGraphic(int len)
{
int[] colors= new int[len];
for(int i =0;i<len;i++)
{
colors[i]=(int) Math.round(Math.random()*80)+colorLid;
}
colorLid+=4;
return new ColorDotsGraphic(colors);
}
private int count =1;
private int instanceCount =0;
public void update()
{
if(instanceCount<90 && count % 20==0)
{
instanceCount++;
Graphic h=addGraphic("myrandoms_"+instanceCount, makeGraphic(_len));
h.position = instanceCount*(_len+100);
//println("one more " + instanceCount+" at "+h.position);
count=0;
changed = true;
}
count++;
super.update();
}
};
class ColorDotsGraphic extends Graphic
{
ColorDotsGraphic(int[] colorSequence)
{
super();
for (int colorVal : colorSequence)
{
graphicBuffer.add(color(colorVal, 255, 255));
}
changed = true;
}
};