Working recursive display - not yet fast
authorBen Morrow <childoftv@gmail.com>
Sun, 18 Aug 2013 04:12:10 +0000 (21:12 -0700)
committerBen Morrow <childoftv@gmail.com>
Sun, 18 Aug 2013 04:12:10 +0000 (21:12 -0700)
BenMorrow.pde
GranimPattern.pde
SugarCubes.pde

index 67a1b79c317f7c21d21d0fd84c9b246da00b5426..911f886fef8661075837c690aa78f4ef0320d9b9 100644 (file)
@@ -48,16 +48,66 @@ class GranimTestPattern extends GranimPattern
        GranimTestPattern(GLucose glucose)
        {
                super(glucose);
-               RedThreeGraphic myReds = new RedThreeGraphic();
-               addGraphic("myThreeReds",myReds);
+               addGraphic("myReds",new RedsGraphic(100));
+               int[] dots = {0,128,0,128,0,128,0,128,0,128,0,128};
+               addGraphic("myOtherColors",new ColorDotsGraphic(dots));
+
+               getGraphicByName("myOtherColors").position=100;
        }
        int counter=0;
        public void run(int deltaMs) 
        {
+               clearALL();
                super.run(deltaMs);
+               
                if(counter % 3 ==0)
                {
-                       getGraphicByName("myThreeReds").position++;
+                       Graphic reds = getGraphicByName("myReds");
+                       Graphic others = getGraphicByName("myOtherColors");
+                       reds.position = reds.position + 1 % 19000;
+                       others.position = others.position + 10 % 19000;
+               }
+       }
+       public void clearALL()
+       {
+               for(Point p : model.points)
+               {
+                       colors[p.index] = 0;
+               }
+       }
+
+
+}
+
+class GranimTestPattern2 extends GranimPattern
+{
+       GranimTestPattern2(GLucose glucose)
+       {
+               super(glucose);
+               /*for(int i = 0;i < 100; i++)
+               {
+                       Graphic g = addGraphic("myReds_"+i,new RedsGraphic(Math.round(Math.random() * 100)));
+
+               }*/
+               Graphic g = addGraphic("myRandoms",new RandomsGranim(50));
+               g.position = 200;
+               
+       }
+       int counter=0;
+       float count=0;
+       public void run(int deltaMs) 
+       {
+               clearALL();
+               super.run(deltaMs);
+               Graphic randomsGraphic = getGraphicByName("myRandoms");
+               randomsGraphic.position = Math.round(sin(count)*1000)+5000;
+               count+= 0.0005;
+       }
+       public void clearALL()
+       {
+               for(Point p : model.points)
+               {
+                       colors[p.index] = 0;
                }
        }
 
index 99d8f402fbdb4dc525f7635adc196fc696cf911a..c2f9fc0d0aa4d2c043b41526c9959da50d9e141c 100644 (file)
@@ -1,29 +1,88 @@
-import java.util.Hashtable;
+import java.util.LinkedHashMap;
 class Graphic
 {
        public int position  = 0;
        public ArrayList<Integer> graphicBuffer;
-
        Graphic()
        {       
                graphicBuffer = new ArrayList<Integer>();
        }
+       public int width()
+       {
+               return graphicBuffer.size();
+       }
 
        
+};
+class Granim extends Graphic
+{
+       LinkedHashMap<String,Graphic> displayList;
+       
+       Granim()
+       {
+               displayList = new LinkedHashMap<String,Graphic>();
+       }
+       public Graphic addGraphic(String name, Graphic g)
+       {
+               graphicBuffer.clear();
+               while(width()< g.position+1)
+               {
+                               graphicBuffer.add(color(0,0,0));
+               }
+               drawAll();
+               displayList.put(name , g);
+               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();
+                       }
+               }
+               drawAll();
+
+       }
+       public void drawOne(Graphic g)
+       {
+               graphicBuffer.addAll(g.position,g.graphicBuffer);
+       }
+       public void drawAll()
+       {
+               graphicBuffer.clear();
+               for(Graphic g : displayList.values())
+               {
+                       while(width()< g.position + g.width())
+                       {
+                               graphicBuffer.add(color(0,0,0));
+                       }
+                       drawOne(g);
+               }
+       }
 };
 class GranimPattern extends SCPattern
 {
-       Hashtable<String,Graphic> displayList;
+       LinkedHashMap<String,Graphic> displayList;
 
        GranimPattern(GLucose glucose)
        {
                super(glucose);
-               displayList = new Hashtable<String,Graphic>();
+               displayList = new LinkedHashMap<String,Graphic>();
        }
 
-       public void addGraphic(String name, Graphic g)
+       public Graphic addGraphic(String name, Graphic g)
        {
                displayList.put(name,g);
+               return g;
        }
 
        public Graphic getGraphicByName(String name)
@@ -32,10 +91,19 @@ class GranimPattern extends SCPattern
        }
 
        public void run(int deltaMs) 
+       {
+               drawToPointList();
+       }
+
+       public void drawToPointList()
        {
                for(Graphic g : displayList.values())
                {
-                       List<Point> drawList = model.points.subList(g.position, g.position + g.graphicBuffer.size());
+                       if(g instanceof Granim)
+                       {
+                               ((Granim) g).update();
+                       }
+                       List<Point> drawList = model.points.subList(g.position, g.position + g.width());
 
                        for (int i=0; i < drawList.size(); i++)
                        {
@@ -46,18 +114,107 @@ class GranimPattern extends SCPattern
 
 };
 
-class RedThreeGraphic extends Graphic
+class RedsGraphic extends Graphic
 {
-       RedThreeGraphic()
+       RedsGraphic()
        {
                super();
-               prepare();
+               drawit(10);
        }
-       public void prepare()
+       RedsGraphic(int len)
        {
-               for(int i=0; i < 3 ;i++)
+               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));
+       }
+       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));
+               }
+       }
+};
index ae1976750348603c6db8eaf0de346505c3c395df..4222846297b84a95ad95d348dbaaf7ae1dde74c2 100644 (file)
@@ -25,6 +25,7 @@
 
 LXPattern[] patterns(GLucose glucose) {
   return new LXPattern[] {
+    new GranimTestPattern2(glucose),
     new GranimTestPattern(glucose),
     new Sandbox(glucose),
     new HelixPattern(glucose),