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