From: Ben Morrow Date: Mon, 19 Aug 2013 02:59:05 +0000 (-0700) Subject: Merge branch 'master' of github.com:sugarcubes/SugarCubes into BenMorrow X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=1adfd26520e2d62cc85788624f711a86614f4c3b;hp=9b893d9614672cc7ec0e9ed8e9e67388737a3c17;p=SugarCubes.git Merge branch 'master' of github.com:sugarcubes/SugarCubes into BenMorrow --- diff --git a/BenMorrow.pde b/BenMorrow.pde new file mode 100644 index 0000000..9294250 --- /dev/null +++ b/BenMorrow.pde @@ -0,0 +1,178 @@ +class Sandbox extends SCPattern +{ + int c=0; + int prevC=0; + int huerange=255; + int pointrange= model.points.size(); + int striprange= model.strips.size(); + int facerange= model.faces.size(); + int cuberange = model.cubes.size(); + int towerrange = model.towers.size(); + int counter=0; + + Sandbox(GLucose glucose) { + super(glucose); + println("points "+pointrange); + println("strips "+striprange); + println("faces "+facerange); + println("cubes "+cuberange); + println("towers "+towerrange); + } + + public void run(int deltaMs) { + + + if(counter % 10 ==0) + { + doDraw(c,0); + c = (c + 1) % towerrange; + long col = color(Math.round(Math.random()*255),255,255) ; + doDraw(c,col); + } + counter++; + + } + + public void doDraw(int c,long col) + { + Tower t= model.towers.get((int) c); + for(Point p : t.points) + { + colors[p.index] = (int) col; + } + } +}; + +class GranimTestPattern extends GranimPattern +{ + GranimTestPattern(GLucose glucose) + { + super(glucose); + 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) + { + Graphic reds = getGraphicByName("myReds"); + Graphic others = getGraphicByName("myOtherColors"); + reds.position = reds.position + 1 % 19000; + others.position = others.position + 10 % 19000; + } + } + public void clearALL() + { + for(int i = 0; i < colors.length; i++) + { + colors[i] = 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.005; + } + public void clearALL() + { + for(Point p : model.points) + { + colors[p.index] = 0; + } + } + + +}; + +class DriveableCrossSections extends CrossSections +{ + BasicParameter xd; + BasicParameter yd; + BasicParameter zd; + BasicParameter mode; + + DriveableCrossSections(GLucose glucose) { + super(glucose); + } + + public void addParams() + { + mode = new BasicParameter("Mode", 0.0); + xd = new BasicParameter("XD", 0.0); + yd = new BasicParameter("YD", 0.0); + zd = new BasicParameter("ZD", 0.0); + addParameter(mode); + addParameter(xd); + addParameter(yd); + addParameter(zd); + addParameter(xr); + addParameter(yr); + addParameter(zr); + addParameter(xw); + addParameter(xl); + addParameter(yl); + addParameter(zl); + addParameter(yw); + addParameter(zw); + } + + public void onParameterChanged(LXParameter p) { + if(p == mode) + { + if(interactive()) + { + xd.setValue(x.getValue()/200); + yd.setValue(y.getValue()/200); + zd.setValue(z.getValue()/100); + } + } + } + + boolean interactive() + { + return Math.round(mode.getValuef())>0.5; + } + + public void updateXYZVals() + { + if(interactive()) + { + xv = xd.getValuef()*200; + yv = yd.getValuef()*200; + zv = zd.getValuef()*100; + }else{ + super.updateXYZVals(); + } + } + +} \ No newline at end of file diff --git a/GranimPattern.pde b/GranimPattern.pde new file mode 100644 index 0000000..0a34baf --- /dev/null +++ b/GranimPattern.pde @@ -0,0 +1,232 @@ +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(color(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(color(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 +{ + HashMap displayList; + + GranimPattern(GLucose glucose) + { + super(glucose); + displayList = new HashMap(); + } + + public Graphic addGraphic(String name, Graphic g) + { + displayList.put(name,g); + return g; + } + + public Graphic getGraphicByName(String name) + { + return displayList.get(name); + } + + public void run(int deltaMs) + { + drawToPointList(); + } + private Integer[] gbuffer; + public void drawToPointList() + { + for(Graphic g : displayList.values()) + { + 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] = gbuffer[i]; + } + g.changed =false; + } + } + +}; + +class RedsGraphic extends Graphic +{ + RedsGraphic() + { + super(); + drawit(10); + } + RedsGraphic(int len) + { + 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