+
+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));
+ }
+ public Graphic makeGraphic(int len)
+ {
+ int[] colors= new int[len];
+ for(int i =0;i<len;i++)
+ {
+ colors[i]=(int) Math.round(Math.random()*255);
+ }
+ return new ColorDotsGraphic(colors);
+ }
+ private int count =1;
+ private int instanceCount =0;
+ public void update()
+ {
+ super.update();
+ if(count % 50==0)
+ {
+ instanceCount++;
+ Graphic h=addGraphic("myrandoms_"+instanceCount, makeGraphic(_len));
+ h.position = instanceCount*(_len+100);
+ println("one more " + instanceCount+" at "+h.position);
+ count=0;
+ }
+ count++;
+
+ }
+
+};
+
+
+class ColorDotsGraphic extends Graphic
+{
+ ColorDotsGraphic(int[] colorSequence)
+ {
+ super();
+ for (int colorVal : colorSequence)
+ {
+ graphicBuffer.add(color(colorVal, 255, 255));
+ }
+ }
+};