X-Git-Url: https://git.piment-noir.org/?p=SugarCubes.git;a=blobdiff_plain;f=GranimPattern.pde;h=da4c78f3955fbb1831ce6fab4532c20989acf3c4;hp=2fd33e15c2a0541caef2d33fc09ddea8c70af1af;hb=8f4e6c99775f2724edf3cec488860eb68b06491c;hpb=2ca063885e4bcf5c22f48c396959b37417694a6a diff --git a/GranimPattern.pde b/GranimPattern.pde index 2fd33e1..da4c78f 100644 --- a/GranimPattern.pde +++ b/GranimPattern.pde @@ -1,58 +1,236 @@ -import java.util.Hashtable; +import java.util.LinkedHashMap; class Graphic { + public boolean changed = false; public int position = 0; public ArrayList graphicBuffer; - Graphic() { graphicBuffer = new ArrayList(); } + public int width() + { + return graphicBuffer.size(); + } +}; +class Granim extends Graphic +{ + HashMap displayList; + + Granim() + { + displayList = new HashMap(); + } + public Graphic addGraphic(String name, Graphic g) + { + while(width()< g.position+1) + { + graphicBuffer.add(lx.hsb(0,0,0)); + } + drawAll(); + displayList.put(name , g); + changed =true; + 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(); + + } + changed = changed || g.changed; + if(changed) + { + while(width()< g.position + g.width()) + { + graphicBuffer.add(lx.hsb(0,0,0)); + } + if(g.changed) + { + drawOne(g); + g.changed =false; + } + } + } + changed = false; + + } + public void drawOne(Graphic g) + { + graphicBuffer.addAll(g.position,g.graphicBuffer); + } + public void drawAll() + { + } }; class GranimPattern extends SCPattern { - Hashtable displayList; + HashMap displayList; GranimPattern(GLucose glucose) { super(glucose); - displayList = new Hashtable(); + displayList = new HashMap(); } - public void addGraphic(String name, Graphic g) + public Graphic addGraphic(String name, Graphic g) { displayList.put(name,g); + return g; } - public void run(int deltaMs) + public Graphic getGraphicByName(String name) + { + return displayList.get(name); + } + + public void run(double deltaMs) + { + drawToPointList(); + } + private Integer[] gbuffer; + public void drawToPointList() { for(Graphic g : displayList.values()) { - List drawList = model.points.subList(g.position, g.position + g.graphicBuffer.size()); - + if(g instanceof Granim) + { + ((Granim) g).update(); + } + List drawList = model.points.subList(Math.min(g.position,colors.length-1), Math.min(g.position + g.width(),colors.length-1)); + //println("drawlistsize "+drawList.size()); + + gbuffer = g.graphicBuffer.toArray(new Integer[0]); + for (int i=0; i < drawList.size(); i++) { - colors[drawList.get(i).index] = (int) g.graphicBuffer.get(i); + colors[drawList.get(i).index] = gbuffer[i]; } + g.changed = false; } } }; -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(lx.hsb(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)); + } + int colorLid=0; + public Graphic makeGraphic(int len) + { + + int[] colors= new int[len]; + for(int i =0;i