Add huespan limit and hueoffset
[SugarCubes.git] / BenMorrow.pde
1 class TowerParams extends SCPattern
2 {
3 BasicParameter hueoff = new BasicParameter("Hueoff", 0.0);
4 BasicParameter hueSpan = new BasicParameter("HueRange", 0.0);
5 BasicParameter t1 = new BasicParameter("T1", 0.0);
6 BasicParameter t2 = new BasicParameter("T2", 0.0);
7 BasicParameter t3 = new BasicParameter("T3", 0.0);
8 BasicParameter t4 = new BasicParameter("T4", 0.0);
9 BasicParameter t5 = new BasicParameter("T5", 0.0);
10 BasicParameter t6 = new BasicParameter("T6", 0.0);
11 BasicParameter t7 = new BasicParameter("T7", 0.0);
12 BasicParameter t8 = new BasicParameter("T8", 0.0);
13 BasicParameter t9 = new BasicParameter("T9", 0.0);
14 BasicParameter t10 = new BasicParameter("T10", 0.0);
15 BasicParameter t11 = new BasicParameter("T11", 0.0);
16 BasicParameter t12 = new BasicParameter("T12", 0.0);
17 BasicParameter t13 = new BasicParameter("T13", 0.0);
18 BasicParameter t14 = new BasicParameter("T14", 0.0);
19 BasicParameter t15 = new BasicParameter("T15", 0.0);
20 BasicParameter t16 = new BasicParameter("T16", 0.0);
21
22 ArrayList<BasicParameter> towerParams;
23 int towerSize;
24 int colorSpan;
25 TowerParams(GLucose glucose) {
26 super(glucose);
27
28 towerParams = new ArrayList<BasicParameter>();
29 addParameter(hueoff);
30 addParameter(hueSpan);
31 towerParams.add(t1);
32 towerParams.add(t2);
33 towerParams.add(t3);
34 towerParams.add(t4);
35 towerParams.add(t5);
36 towerParams.add(t6);
37 towerParams.add(t7);
38 towerParams.add(t8);
39 towerParams.add(t9);
40 towerParams.add(t10);
41 towerParams.add(t11);
42 towerParams.add(t12);
43 towerParams.add(t13);
44 towerParams.add(t14);
45 towerParams.add(t15);
46 towerParams.add(t16);
47 for(BasicParameter p : towerParams)
48 {
49 addParameter(p);
50 }
51 towerSize = model.towers.size();
52 colorSpan = 255 / towerSize;
53 println("towers "+towerSize);
54 }
55
56 void run(int deltaMs)
57 {
58 clearALL();
59 Tower t;
60 for(int i=0; i<towerSize ;i++)
61 {
62 t= model.towers.get(i);
63 for(Point p : t.points)
64 {
65 if(p.y<towerParams.get(i).getValuef()*200)
66 {
67 colors[p.index]=color(255 * hueoff.getValuef()+colorSpan * hueSpan.getValuef() * i,255,255);
68 }
69 }
70 }
71
72 }
73
74 public void clearALL()
75 {
76 for(Point p : model.points)
77 {
78 colors[p.index] = 0;
79 }
80 }
81
82 }
83 class Sandbox extends SCPattern
84 {
85 int c=0;
86 int prevC=0;
87 int huerange=255;
88 int pointrange= model.points.size();
89 int striprange= model.strips.size();
90 int facerange= model.faces.size();
91 int cuberange = model.cubes.size();
92 int towerrange = model.towers.size();
93 int counter=0;
94
95 Sandbox(GLucose glucose) {
96 super(glucose);
97 println("points "+pointrange);
98 println("strips "+striprange);
99 println("faces "+facerange);
100 println("cubes "+cuberange);
101 println("towers "+towerrange);
102 }
103
104 public void run(int deltaMs) {
105
106
107 if(counter % 10 ==0)
108 {
109 doDraw(c,0);
110 c = (c + 1) % towerrange;
111 long col = color(Math.round(Math.random()*255),255,255) ;
112 doDraw(c,col);
113 }
114 counter++;
115
116 }
117
118 public void doDraw(int c,long col)
119 {
120 Tower t= model.towers.get((int) c);
121 for(Point p : t.points)
122 {
123 colors[p.index] = (int) col;
124 }
125 }
126 };
127
128 class GranimTestPattern extends GranimPattern
129 {
130 GranimTestPattern(GLucose glucose)
131 {
132 super(glucose);
133 addGraphic("myReds",new RedsGraphic(100));
134 int[] dots = {0,128,0,128,0,128,0,128,0,128,0,128};
135 addGraphic("myOtherColors",new ColorDotsGraphic(dots));
136
137 getGraphicByName("myOtherColors").position=100;
138 }
139 int counter=0;
140 public void run(int deltaMs)
141 {
142 clearALL();
143 super.run(deltaMs);
144
145 if(counter % 3 ==0)
146 {
147 Graphic reds = getGraphicByName("myReds");
148 Graphic others = getGraphicByName("myOtherColors");
149 reds.position = reds.position + 1 % 19000;
150 others.position = others.position + 10 % 19000;
151 }
152 }
153 public void clearALL()
154 {
155 for(int i = 0; i < colors.length; i++)
156 {
157 colors[i] = 0;
158 }
159 }
160
161
162 }
163
164 class GranimTestPattern2 extends GranimPattern
165 {
166 GranimTestPattern2(GLucose glucose)
167 {
168 super(glucose);
169 /*for(int i = 0;i < 100; i++)
170 {
171 Graphic g = addGraphic("myReds_"+i,new RedsGraphic(Math.round(Math.random() * 100)));
172
173 }*/
174 Graphic g = addGraphic("myRandoms",new RandomsGranim(50));
175 g.position = 200;
176
177 }
178 int counter=0;
179 float count=0;
180 public void run(int deltaMs)
181 {
182 clearALL();
183 super.run(deltaMs);
184 Graphic randomsGraphic = getGraphicByName("myRandoms");
185 randomsGraphic.position = Math.round(sin(count)*1000)+5000;
186 count+= 0.005;
187 }
188 public void clearALL()
189 {
190 for(Point p : model.points)
191 {
192 colors[p.index] = 0;
193 }
194 }
195
196
197 };
198
199 class DriveableCrossSections extends CrossSections
200 {
201 BasicParameter xd;
202 BasicParameter yd;
203 BasicParameter zd;
204 BasicParameter mode;
205
206 DriveableCrossSections(GLucose glucose) {
207 super(glucose);
208 }
209
210 public void addParams()
211 {
212 mode = new BasicParameter("Mode", 0.0);
213 xd = new BasicParameter("XD", 0.0);
214 yd = new BasicParameter("YD", 0.0);
215 zd = new BasicParameter("ZD", 0.0);
216 addParameter(mode);
217 addParameter(xd);
218 addParameter(yd);
219 addParameter(zd);
220
221 super.addParams();
222 }
223
224 public void onParameterChanged(LXParameter p) {
225 if(p == mode)
226 {
227 if(interactive())
228 {
229 copyValuesToKnobs();
230 }else{
231 copyKnobsToValues();
232 }
233 }
234 }
235
236 void copyValuesToKnobs()
237 {
238 xd.setValue(x.getValue()/200);
239 yd.setValue(y.getValue()/115);
240 zd.setValue(z.getValue()/100);
241 }
242
243 void copyKnobsToValues()
244 {
245 x.setValue(xd.getValue()*200);
246 y.setValue(yd.getValue()*115);
247 z.setValue(zd.getValue()*100);
248 }
249
250 boolean interactive()
251 {
252 return Math.round(mode.getValuef())>0.5;
253 }
254
255 public void updateXYZVals()
256 {
257 if(interactive())
258 {
259 xv = xd.getValuef()*200;
260 yv = yd.getValuef()*115;
261 zv = zd.getValuef()*100;
262 }else{
263 super.updateXYZVals();
264 copyValuesToKnobs();
265 }
266 }
267
268 }