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