• fullscreen
  • Toy_for_architects2_0.pde
  • attractor.pde
  • control_ip5.pde
  • kamara.pde
  • particle.pde
  • threepoint.pde
  • toxic.pde
  • import toxi.physics.*;
    import toxi.physics.constraints.*;
    import toxi.physics.behaviors.*;
    
    import toxi.volume.*;
    import toxi.math.conversion.*;
    import toxi.geom.*;
    import toxi.math.*;
    import toxi.util.datatypes.*;
    import toxi.util.events.*;
    import toxi.geom.mesh.subdiv.*;
    import toxi.geom.mesh.*;
    import toxi.math.waves.*;
    import toxi.util.*;
    import toxi.math.noise.*;
    import peasy.*;
    
    
    
    boolean ko=false;
    boolean voxelallow=false;
    ArrayList Punkt=new ArrayList();
    ArrayList Linie=new ArrayList();
    ArrayList choose=new ArrayList();
    ArrayList Flaeche=new ArrayList();
    boolean reception,Lauf=false;
    float Nord=1;
    float REST_LENGTH;
    float STRENGTH=0.125;
    int pcount=0,scount=0;
    boolean cat=true,Setupgrowthpoint=true;
    float ca=7;
    
    void setup()
    {
      size (1280, 700, P3D);
      REST_LENGTH=gro;
      initPhysics();
      gfx = new ToxiclibsSupport(this);
      setupGUI ();
      smooth();
      strokeWeight (1);
      stroke(255);
      Dog.add (new attractor(-s13/2, s13/2));
      Cat.add (new earthpoint(s13/2, s13/2));
      Donkey.add (new Growthpoint(0, 0)); 
      Fish.add (new Boundary(0, 0)); 
      
      setupCamera ();
    }
    void draw()
    {
    
    
      
      ///////////////
      int Acount=0,Bcount=0,Ccount=0;
      reception=true;
      Vec3D Cpunkt=new Vec3D();
      background (0);
      float counterboard;
      drawCamera ();
      Vec3D Npunkt=new Vec3D (-sin(Npa)*s13/2,cos(Npa)*s13/2,0);
    
      //////////////
      if (Lauf==true)
      {
        if (Setupgrowthpoint)
        {
          for (int i =0; i < Donkey.size (); i=i+1)
          {
            Growthpoint b = (Growthpoint)Donkey.get (i);
            if (b.run)
            {
              Vec3D A = new Vec3D (b.A, b.B, 0);
              Punkt.add (new onepoint (A));
              VerletParticle Ap=new VerletParticle (A);
              pcount++;
              Vec3D B = new Vec3D (b.A+gro, b.B, 0);
              Punkt.add (new onepoint (B));
              VerletParticle Bp=new VerletParticle (B);
              pcount++;
              Vec3D C = new Vec3D (b.A+gro/2, gro/2*sqrt(3)+b.B, 0);
              Punkt.add (new onepoint (C));
              VerletParticle Cp=new VerletParticle (C);
              pcount++;
              
              physics.addParticle(Ap);
              physics.addParticle(Bp);
              physics.addParticle(Cp);
              physics.addSpring(new VerletSpring(Ap,Bp,REST_LENGTH,STRENGTH));
              physics.addSpring(new VerletSpring(Cp,Bp,REST_LENGTH,STRENGTH));
              physics.addSpring(new VerletSpring(Cp,Ap,REST_LENGTH,STRENGTH));
              
              Linie.add (new twopoint(A, B));
              scount++;
              Linie.add (new twopoint(B, C));
              scount++;
              Linie.add (new twopoint(C, A));
              scount++;
              
              threepoint erstf=new threepoint (A,B,C);
              erstf.pc1=0;
              erstf.pc2=1;
              erstf.pc3=2;
              Flaeche.add (erstf);
            }
    
          }
          
          Setupgrowthpoint=!Setupgrowthpoint;
        }
        
        choose=new ArrayList();
        for(int i=0;i<Linie.size();i=i+1)
        {
          twopoint a = (twopoint)Linie.get (i);
          if(a.counterChilds==1)
          {
            choose.add (a);
          }
        }
        int numtmp1= int (random ( choose.size ()));
        twopoint b = (twopoint)choose.get (numtmp1);
        twopoint MyLinie = (twopoint)Linie.get (b.sc);
    
    //    int numtmp1= int (random ( Linie.size ()));
    //    twopoint MyLinie = (twopoint)Linie.get (numtmp1);
    //    println(scount);
        
        /////////////richtungcontroler
        if  (MyLinie.counterChilds<2)
        {
        //////////////////////
          for(int i=0;i<Flaeche.size();i=i+1)
          {
            threepoint a=(threepoint)Flaeche.get(i);
            if (MyLinie.A.distanceTo(a.A)<3||MyLinie.A.distanceTo(a.B)<3||MyLinie.A.distanceTo(a.C)<3)
            {
              if (MyLinie.B.distanceTo(a.A)<3||MyLinie.B.distanceTo(a.B)<3||MyLinie.B.distanceTo(a.C)<3)
              {
                if (a.A!=MyLinie.A&&a.A!=MyLinie.B)
                {
                  Cpunkt=new Vec3D (a.A.x,a.A.y,a.A.z);
                }
                else if (a.B!=MyLinie.A&&a.B!=MyLinie.B)
                {
                  Cpunkt=new Vec3D (a.B.x,a.B.y,a.B.z);
                }
                else
                {
                  Cpunkt=new Vec3D (a.C.x,a.C.y,a.C.z);
                }
              
              }
            }
          }
             /////////////////////
          Vec3D richtungsVektor1= MyLinie.A.sub(Cpunkt);
          Vec3D richtungsVektor2= MyLinie.B.sub(Cpunkt);
          Vec3D richtungsVektor3=richtungsVektor1.add(richtungsVektor2);
          Vec3D drittepunkt=richtungsVektor3.add(Cpunkt);
          ////////////////////////
          boolean ifinside=false;
          for (int i =0; i < Fish.size (); i=i+1)
          {
            Boundary c = (Boundary)Fish.get (i);
            Vec3D d=new Vec3D(c.A,c.B,0);
            if (drittepunkt.distanceTo(d)<=c.R)
            {
              ifinside=true;
            }
          }
    
          if (ifinside)
          {
            for(int i=0;i<Punkt.size();i=i+1)
            {
              onepoint a=(onepoint)Punkt.get(i);
              if (a.A.distanceTo(MyLinie.A)<1||a.A.distanceTo(MyLinie.B)<1||a.A.distanceTo(drittepunkt)<1)
              {
                whichone(drittepunkt);
                Boundary btemp=(Boundary)Fish.get (which);
                Npunkt=new Vec3D (-sin(btemp.Npp)*btemp.R+btemp.A,cos(btemp.Npp)*btemp.R+btemp.B,0);
                float d= a.A.distanceTo(Npunkt);
                counterboard=map(d,0,2*btemp.R,4,7);
                if (a.counterChilds>counterboard-1)
                {
                  reception=false;
                }
              }
            }
          /////////////////////
    //      println(reception);
            if (reception==true)
            {
              MyLinie.counterChilds++;
              for(int i=0;i<Punkt.size();i=i+1)
              {
                onepoint a=(onepoint)Punkt.get(i);
                if (a.A.distanceTo(MyLinie.A)<1||a.A.distanceTo(MyLinie.B)<1||a.A.distanceTo(drittepunkt)<ca)
                {
                  a.counterChilds++;
                  if (a.A.distanceTo(drittepunkt)<ca)
                  {
                    drittepunkt=a.A;
                  }
                  if(a.A.distanceTo(MyLinie.A)<1)
                  {
                    Acount=a.pc;
                  }
                  if(a.A.distanceTo(MyLinie.B)<1)
                  {
                    Bcount=a.pc;
    //                println(Bcount);
                  }
                //println(a.counterChilds);
                }
              }
              
              //////////////
    //          Vec3D a1=new Vec3D(MyLinie.A.x,MyLinie.A.y,0);
    //          Vec3D b1=new Vec3D(MyLinie.B.x,MyLinie.B.y,0);
    //          Vec3D c1=new Vec3D(drittepunkt.x,drittepunkt.y,0);
              ///////////////
              
              int pp=0;
              for(int i=0;i<Punkt.size();i=i+1)
              {
                onepoint a=(onepoint)Punkt.get(i);
                if (a.A.distanceTo(drittepunkt)<1)
                {
                  cat=false;
                  pp=i;
                  Ccount=i;
    
                }
              }
              VerletParticle App=physics.particles.get(Acount);
              VerletParticle Bpp=physics.particles.get(Bcount);
              if (cat)
              { 
                VerletParticle drittepunktp=new VerletParticle (drittepunkt);
                Punkt.add (new onepoint (drittepunkt));
                Ccount=pcount;
                pcount++;
                physics.addParticle(drittepunktp); 
                Linie.add (new twopoint(drittepunkt, MyLinie.A));
                scount++;
                physics.addSpring(new VerletSpring(App,drittepunktp,REST_LENGTH,STRENGTH));
                Linie.add (new twopoint(drittepunkt, MyLinie.B));
                scount++;
                physics.addSpring(new VerletSpring(Bpp,drittepunktp,REST_LENGTH,STRENGTH));
              }
              if (!cat)
              {
                cat=true;
                boolean addline=true;
                VerletParticle drittepunktp=physics.particles.get(pp);
                for(int i=0;i<Linie.size();i=i+1) 
                {
                  twopoint MyLinie1 = (twopoint)Linie.get (i);
                  if (MyLinie1.A.distanceTo(MyLinie.A)<1&&MyLinie1.B.distanceTo(drittepunkt)<1)
                  {
                    MyLinie1.counterChilds++;
                    addline=false;
                  }
                  if (MyLinie1.B.distanceTo(MyLinie.A)<1&&MyLinie1.A.distanceTo(drittepunkt)<1)
                  {
                    MyLinie1.counterChilds++;
                    addline=false;
                  }
                  
                }
                if (addline)
                {
                  Linie.add (new twopoint(drittepunkt, MyLinie.A));
                  scount++;
                  physics.addSpring(new VerletSpring(App,drittepunktp,REST_LENGTH,STRENGTH));
                }
                addline=true;
                
                for(int i=0;i<Linie.size();i=i+1) 
                {
                  twopoint MyLinie2 = (twopoint)Linie.get (i);
                  if (MyLinie2.A.distanceTo(MyLinie.B)<1&&MyLinie2.B.distanceTo(drittepunkt)<1)
                  {
                    MyLinie2.counterChilds++;
                    addline=false;
                  }
                  if (MyLinie2.B.distanceTo(MyLinie.B)<1&&MyLinie2.A.distanceTo(drittepunkt)<1)
                  {
                    MyLinie2.counterChilds++;
                    addline=false;
                  }
                }
                if (addline)
                {
                  Linie.add (new twopoint(drittepunkt, MyLinie.B));
                  scount++;
                  physics.addSpring(new VerletSpring(Bpp,drittepunktp,REST_LENGTH,STRENGTH));
                }
              }
              threepoint newface=new threepoint (MyLinie.A,MyLinie.B,drittepunkt);
              newface.pc1=Acount;
              newface.pc2=Bcount;
              newface.pc3=Ccount;
              Flaeche.add (newface);
            
            } 
          }
        }
      }
      stroke (255);
      if (!hide)
      {
        for (int i =0; i < Dog.size (); i=i+1)
        {
          attractor b = (attractor)Dog.get (i);
          if (i==Listchoose)
          {
            b.C=false;
          }
          b.drawattractor ();
          b.C=true;
        }
        for (int i =0; i < Fish.size (); i=i+1)
        {
          Boundary b = (Boundary)Fish.get (i);
          if (i==Listchoose-90)
          {
            b.C=false;
          }
          b.drawboundary();
          b.C=true;      
        }
          for (int i =0; i < Cat.size (); i=i+1)
        {
          earthpoint b = (earthpoint)Cat.get (i);
          if (i==Listchoose-30)
          {
            b.C=false;
          }
          b.drawearthpoint ();
          b.C=true;
        }
          for (int i =0; i < Donkey.size (); i=i+1)
        {
          Growthpoint b = (Growthpoint)Donkey.get (i);
          if (i==Listchoose-60)
          {
            b.C=false;
          }
          b.drawgrowthpoint ();
          b.C=true;
        }
      }
      if (!voxelallow&&!ko){
        for (int i =0; i < Flaeche.size (); i=i+1)
        {
          threepoint b = (threepoint)Flaeche.get (i); 
          b.updatepos();
          lights();
          b.drawthreepoint ();
          noLights();
        }
      }
      
      //draw voxel
      if (voxelallow){
        if (wireallow){
          noFill();
          strokeWeight(0.1);
          stroke(255);
          gfx.mesh(mesh);
        }
        else {
          fill(255);
          noStroke();
          lights();
          gfx.mesh(mesh);
          noLights();
        }   
      }
      if (ko&&!voxelallow)
      {
    
        for(int i=0;i<Punkt.size();i=i+1)
        {
          onepoint a=(onepoint)Punkt.get(i);
          if (a.counterChilds<s3)
          {
            VerletParticle ptemp=physics.particles.get(a.pc);
            ptemp.x=a.x;
            ptemp.y=a.y;
            ptemp.z=0;
            ptemp.lock();
          }
          else
          {
            VerletParticle ptemp=physics.particles.get(a.pc);
            ptemp.unlock();
          }
        }
        
        for(Iterator i=physics.springs.iterator(); i.hasNext();) 
        {
          VerletSpring s=(VerletSpring)i.next();
    //      s.setStrength(1);
          stroke(255);
          line(s.a.x,s.a.y,s.a.z,s.b.x,s.b.y,s.b.z);
        }
        for (int i =0; i < Flaeche.size (); i=i+1)
        {
          threepoint b = (threepoint)Flaeche.get (i); 
          b.updateparticle();
          lights();
          b.drawthreepoint ();
          noLights();
        }
        physics.update();
      }
    
      
    drawGUI();
    }
    
    ArrayList Dog=new ArrayList();
    ArrayList Cat=new ArrayList();
    ArrayList Donkey=new ArrayList();
    ArrayList Fish=new ArrayList();
    int which;
    
    float h;
    PVector Craft;
    class attractor extends Vec2D
    {
      float A, B;
      boolean C=true,run=true;
      int counterChilds;
      attractor(float tempA, float tempB)
      {
        super(tempA,tempB);
        A=tempA;
        B=tempB;
      }
      void drawattractor()
      {
        if (run)
        {
          if(C)
          {
            stroke(100,0,0);
            fill(100,0,0);
          }
          else
          {
            stroke(255,0,0);
            fill(255,0,0);
          }
          strokeWeight (1);  
          ellipse (A,B,2,2);
          line (A, B, 0, A, B, 30);
        }
      }
    }
    
    class Boundary extends Vec2D
    {
      float A, B;
      boolean C=true,run=true;
      int counterChilds;
      float R=75,Npp=0;
      Boundary(float tempA, float tempB)
      {
        super(tempA,tempB);
        A=tempA;
        B=tempB;
      }
      void drawboundary()
      {
        if (run)
        {
          noFill();
          if(C)
          {
            stroke(100);
            strokeWeight (1);
            ellipse (A,B,2*R,2*R);
            fill(100);
            ellipse (-sin(Npp)*R+A,cos(Npp)*R+B,3,3);
          }
          else
          {
            R=s13/2;
            Npp=Npa;
            stroke(255);
            strokeWeight (1);
            ellipse (A,B,s13,s13);
            fill(255);
            ellipse (-sin(Npa)*s13/2+A,cos(Npa)*s13/2+B,3,3);
          }
    
        }
      }
    }
    
    class Growthpoint extends Vec2D{
      float A, B;
      boolean C=true,run=true;
      int counterChilds;
      Growthpoint(float tempA, float tempB)
      {
        super(tempA,tempB);
        A=tempA;
        B=tempB;
      }
      void drawgrowthpoint()
      {
        if(run)
        {
          if(Setupgrowthpoint)
          {
            noFill();
            stroke(100);
            beginShape();
            gfx.vertex(new Vec2D(A,B));
            gfx.vertex(new Vec2D(A+gro,B));
            gfx.vertex(new Vec2D(A+gro/2, gro/2*sqrt(3)+B));
            gfx.vertex(new Vec2D(A,B));
            endShape();
          }      
          if(C)
          {
            stroke(0,100,0);
            fill(0,100,0);
          }
          else
          {
            stroke(0,255,0);
            fill(0,255,0);
          }
          strokeWeight (1);
    
          ellipse (A,B,2,2);
          line (A, B, 0, A, B, 30);
        }
      }
    }
    
    class earthpoint extends Vec2D{
      float A, B;
      boolean C=true,run=true;
      int counterChilds;
      earthpoint(float tempA, float tempB)
      {
        super(tempA,tempB);
        A=tempA;
        B=tempB;
      }
      void drawearthpoint()
      {
        if(run)
        {
          if(C)
          {
            stroke(0,0,100);
            fill(0,0,100);
          }
          else
          {
            stroke(0,0,255);
            fill(0,0,255);
          }
          strokeWeight (1);
          ellipse (A,B,2,2);
          line (A, B, 0, A, B, 30);
        }
      }
    }
    void Hug (float x,float y)
    {
      float Craft=0;
      float [] hoch=new float[Dog.size ()];
      for (int i =0; i < Dog.size (); i=i+1)
      {
        attractor b = (attractor)Dog.get (i);
        hoch[i]=0;
        if(b.run)
        {
          PVector c=new PVector(b.A,b.B);
          PVector d=new PVector(x,y);
          PVector j= PVector.sub(c,d);
          float f=j.mag();
          float k=s5*f;
          float g=k+s6;
          hoch[i]=3/g;
        }
      }
      
      for (int i =0; i < Dog.size (); i=i+1)
      {
        Craft=Craft+hoch[i];
      }
      h=Craft*s4;
    }
    
    void whichone (Vec3D x)
    {
      int insidecount=0;
      float distemp=0;
      for (int j =0; j < Fish.size (); j=j+1)
      {
        Boundary c = (Boundary)Fish.get (j);
        Vec3D d=new Vec3D(c.A,c.B,0);
        if (x.distanceTo(d)<=c.R&&c.run)
        {
          distemp=x.distanceTo(d);
          insidecount++;
          which=j;
        }
      }
      if (insidecount>1)
      {
        for (int j =0; j < Fish.size (); j=j+1)
        {
          Boundary c = (Boundary)Fish.get (j);
          Vec3D d=new Vec3D(c.A,c.B,0);
          if(x.distanceTo(d)<distemp&&c.run)
          {
            distemp=x.distanceTo(d);
            which=j;
          }
        }
        
      }
      
    }
    
    import controlP5.*;          // GUI
    ControlP5 controlP5;
    PMatrix3D currCameraMatrix;
    PGraphics3D g3; 
    float s4=2,s5=0.03,s6=0.5,s13=150,gro=10,Npa=0,s1=0.5,s2=2,gravity=0.5,s3=4;
    boolean wireallow=false,hide=false;
    float Listchoose=0;//<30 for Attractor, >30 false for Earthpoint, >60 false for growthpoint
    ListBox l,m,o,p;
    
    int lcounter=1,mcounter=1,ocounter=1,pcounter=1;
    
    
    void setupGUI () {
      g3 = (PGraphics3D)g;
      controlP5 = new ControlP5(this);
    
      controlP5.setColorForeground(85);
      controlP5.setColorBackground(50);
      controlP5.setColorLabel(0xFFFFFF);
      controlP5.setColorValue(0);
      controlP5.setColorActive(180);
      
      
      
      controlP5.addSlider("Elementsize", 5, 20, 10, 10, 50, 130, 12);
      controlP5.addSlider("Boundary", 50, 250,150, 10, 70, 130, 12);
      controlP5.addSlider("Height", 0, 10, 2, 10, 90, 130, 12);
      controlP5.addSlider("Kwert", 0.005, 0.1, 0.03, 10, 110, 130,12);
      controlP5.addSlider("Translationswert", 0, 2, 0.5, 10, 130, 130, 12);
      controlP5.addSlider("minOffset", 0, 1, 0.5, 10, 150, 130, 12);
      controlP5.addSlider("verdicalOffset", 0, 10, 2, 10, 170, 130, 12);
      controlP5.addSlider("Magnet", 3, 10, 7, 10, 190, 130, 12);
      controlP5.addSlider("Gravity", 0, 4, 0.5, 10, 210, 130, 12);
      controlP5.addSlider("tolockthemontheground", 2, 6, 4, 10, 230, 130, 12);
      
      controlP5.addKnob("Nordpoint",0,2,0.5,10,550,100);
      controlP5.addToggle("RUN or Stop",false,10,10,20,20);
      /////////////////////
      //voxel
      controlP5.addToggle("Voxelize",false,width-150,10,20,20);
      controlP5.addToggle("Wireform",false,width-50,10,20,20);
      controlP5.addToggle("Hangingsystem",false,width-250,10,20,20);
      ///////////////////////
      //Boundary wahlen
      p = controlP5.addListBox("BoundaryL",280,25,75,45);
      p.setItemHeight(15);
      p.setBarHeight(15);
    
      p.captionLabel().toUpperCase(true);
      p.captionLabel().set("Boundary List");
      p.captionLabel().style().marginTop = 3;
      p.valueLabel().style().marginTop = 3;
      p.addItem("Boundary "+1,90);
      
      //attractor wahlen
      l = controlP5.addListBox("AttractorL",380,25,75,45);
      l.setItemHeight(15);
      l.setBarHeight(15);
    
      l.captionLabel().toUpperCase(true);
      l.captionLabel().set("Attractor List");
      l.captionLabel().style().marginTop = 3;
      l.valueLabel().style().marginTop = 3;
      l.addItem("attractor "+1,0);
    
      
      //Earthpoint wahlen
      m = controlP5.addListBox("EarthpointL",480,25,75,45);
      m.setItemHeight(15);
      m.setBarHeight(15);
    
      m.captionLabel().toUpperCase(true);
      m.captionLabel().set("Earthpoint List");
      m.captionLabel().style().marginTop = 3;
      m.valueLabel().style().marginTop = 3;
      m.addItem("earthpoint "+1,30);
    
      //Growpoint wahlen
      o = controlP5.addListBox("GrowthpointL",580,25,85,45);
      o.setItemHeight(15);
      o.setBarHeight(15);
    
      o.captionLabel().toUpperCase(true);
      o.captionLabel().set("Growthpoint List");
      o.captionLabel().style().marginTop = 3;
      o.valueLabel().style().marginTop = 3;
      o.addItem("growthpoint "+1,60);
    
      
      
      ///////////////////add and delete reactor
      controlP5.addButton("Add Reactor",1,700,10,63,20);
      controlP5.addButton("Rmv Reactor",1,780,10,63,20);
      controlP5.addButton("Hide/Show Reactor",1,860,10,95,20);
    
    
    }
    void controlEvent(ControlEvent theEvent) {
      if(theEvent.isGroup()){
        Listchoose=theEvent.group().value();
        println(Listchoose);
        if (Listchoose>=90)
        {
          Boundary b = (Boundary)Fish.get (int(Listchoose-90));
          controlP5.controller("Boundary").setValue(b.R*2);
          controlP5.controller("Nordpoint").setValue(b.Npp/PI+0.5);
        }   
      }
      if(theEvent.isController()) {
        if(theEvent.controller().name()=="Hangingsystem") {
          ko=!ko;
        }
        if(theEvent.controller().name()=="Hide/Show Reactor") {
          hide=!hide;
        }
        if(theEvent.controller().name()=="Voxelize") {
          voxelallow=!voxelallow;
          
          if (voxelallow&&Lauf){
            controlP5.controller("RUN or Stop").setValue(0);   
          }
          if (voxelallow==true){ 
            boundd();
            setupStructure();
            for (int i =0; i < Flaeche.size (); i=i+1)
            {
              threepoint b = (threepoint)Flaeche.get (i); 
              b.sendmesh ();
            }
            voxelizemesh();
          }
        }
        if(theEvent.controller().name()=="RUN or Stop") {
          Lauf=!Lauf;
          if (Lauf&&voxelallow){
            controlP5.controller("Voxelize").setValue(0);
          }
        }
        if(theEvent.controller().name()=="tolockthemontheground")
        {
          for(int i=0;i<Punkt.size();i=i+1)
          {
            onepoint a=(onepoint)Punkt.get(i);
            if (a.counterChilds<s3)
            {
              VerletParticle ptemp=physics.particles.get(a.pc);
              ptemp.z=0;
              ptemp.lock();
            }
            else
            {
              VerletParticle ptemp=physics.particles.get(a.pc);
              ptemp.unlock();
            }
          }
        }
        if(theEvent.controller().name()=="Gravity")
        {
          Gy.setForce(Vec3D.Z_AXIS.scale(gravity));
        }
        if(theEvent.controller().name()=="Add Reactor")
        {
          if (Listchoose>=90)
          {
            controlP5.controller("Nordpoint").setValue(0.5);
            pcounter++;
            p.addItem("Boundary "+pcounter, pcounter+89);
            Listchoose=Listchoose+1;
            Fish.add (new Boundary(0, 0));
      
          }
          if (Listchoose<30)
          {
            lcounter++;
            l.addItem("attractor "+lcounter, lcounter-1);
            Dog.add (new attractor(-s13/2, s13/2));
            Listchoose=Listchoose+1;
      
          }
          if (Listchoose>=30&&Listchoose<60)
          {
            mcounter++;
            m.addItem("earthpoint "+mcounter, mcounter+29);
            Cat.add (new earthpoint(s13/2, s13/2));
            Listchoose=Listchoose+1;
          }
          if (Listchoose>=60&&Listchoose<90)
          {
            ocounter++;
            o.addItem("growthpoint "+ocounter, ocounter+59);
            Donkey.add (new Growthpoint(s13/2, -s13/2));
            Listchoose=Listchoose+1;
          }
          
        }
        if(theEvent.controller().name()=="Rmv Reactor")
        {
          if (Listchoose>=90)
          {
            int n=int(Listchoose-89);
            p.removeItem("Boundary "+n);
            Boundary b = (Boundary)Fish.get (int(Listchoose-90));
            b.run=false;
          }
          
          if (Listchoose<30)
          {
            int n=int(Listchoose+1);
            l.removeItem("attractor "+n);
            attractor b = (attractor)Dog.get (int(Listchoose));
            b.run=false;
          }
          if (Listchoose>=30&&Listchoose<60)
          {
            int n=int(Listchoose-29);
            m.removeItem("earthpoint "+n);
            earthpoint b = (earthpoint)Cat.get (int(Listchoose-30));
            b.run=false;
          }
          if (Listchoose>=60&&Listchoose<90)
          {
            int n=int(Listchoose-59);
            o.removeItem("growthpoint "+n);
            Growthpoint b = (Growthpoint)Donkey.get (int(Listchoose-60));
            b.run=false;
          }
          
          
        }
      }
    }
    
    void drawGUI() {
      currCameraMatrix = new PMatrix3D(g3.camera);
      camera();
      controlP5.draw();
      if(!hide){
        if (Listchoose>=90)
        {
          fill(255);
          text("Boundary limits the area in which the project grows",700,45);
        }
        if (Listchoose>=60&&Listchoose<90)
        {
          fill(0,180,0);
          text("Growthpoint is the source of the growwingbuilding",700,45);
        }
        if (Listchoose>=30&&Listchoose<60)
        {
          fill(0,0,180);
          text("Earthpoints make the nearest element low till the ground",700,45);
        }
          if (Listchoose<30)
        {
          fill(180,0,0);
          text("Attractors pull the area arround which higher",700,45);
        }
        fill(180);
        text("choose in the lists and use keyboard W S A D to move the reactor",700,60);
        text("plz wait n push nothing when the computer is runing the voxelprocess ",700,75);
      }
      g3.camera = currCameraMatrix;
    }
    
    void tolockthemontheground (float h) {
      s3 = h;
    }
    void verdicalOffset (float h) {
      s2 = h;
    }
    void Gravity (float h) {
      gravity = h;
    }
    void Magnet (float h) {
      ca = h;
    }
    void minOffset (float h) {
      s1 = h;
    }
    void Elementsize (float h) {
      gro = h;
    }
    void Height (float h) {
      s4 = h;
    }
    void Kwert (float h) {
      s5 = h;
    }
    void Translationswert (float h) {
      s6 = h;
    }
    
    void Boundary (float h) {
      s13 = h;
    }
    
    void Nordpoint (float h) {
      Npa = PI*(h-0.5);
    }
    
    /////////////////////////////////
    
    void Wireform (boolean h) {
      wireallow = h;
    }
    
    
    PeasyCam cam;
    
    void setupCamera () {
      //PeasyCam Variablen
      cam = new PeasyCam(this, 150);
      cam.setMinimumDistance(10);
      cam.setMaximumDistance(1000);
      cam.setRightDragHandler(null);
    
      setPerpetiveView() ;
      topView();
    
    }
    
    void drawCamera () {
    
      if (controlP5.window(this).isMouseOver()) {
        cam.setActive(false);
      } 
      else {
        cam.setActive(true);
      }
    
      hint(ENABLE_DEPTH_TEST);
    }
    void topView() {
      cam.setRotations(0, 0, PI); // pitch,  yaw, roll rotations are applied in that order
    }
    
    
    
    void setPerpetiveView() {
      perspective(PI/3.0, (float)width/height, 1, 100000);
    }
    void keyPressed()
    {
      if (key == 'w' || key == 'W')
      {
        if (Listchoose<30)
        {
          attractor tmp=(attractor)Dog.get (int(Listchoose));
          tmp.B++;
        }
        else if (Listchoose>=30&&Listchoose<60)
        {
          earthpoint tmp=(earthpoint)Cat.get (int(Listchoose-30));
          tmp.B++;
        }
        else if(Listchoose>=60&&Listchoose<90)
        {
          Growthpoint tmp=(Growthpoint)Donkey.get (int(Listchoose-60));
          tmp.B++;
        }
        else 
        {
          Boundary tmp=(Boundary)Fish.get (int(Listchoose-90));
          tmp.B++;
        }
      }
      if (key == 's' || key == 'S')
      {
        if (Listchoose<30)
        {
          attractor tmp=(attractor)Dog.get (int(Listchoose));
          tmp.B--;
        }
        else if (Listchoose>=30&&Listchoose<60)
        {
          earthpoint tmp=(earthpoint)Cat.get (int(Listchoose-30));
          tmp.B--;
        }
        else if(Listchoose>=60&&Listchoose<90)
        {
          Growthpoint tmp=(Growthpoint)Donkey.get (int(Listchoose-60));
          tmp.B--;
        }
        else 
        {
          Boundary tmp=(Boundary)Fish.get (int(Listchoose-90));
          tmp.B--;
        }
      }
      if (key == 'a' || key == 'A')
      {
        if (Listchoose<30)
        {
          attractor tmp=(attractor)Dog.get (int(Listchoose));
          tmp.A++;
        }
        else if (Listchoose>=30&&Listchoose<60)
        {
          earthpoint tmp=(earthpoint)Cat.get (int(Listchoose-30));
          tmp.A++;
        }
        else if(Listchoose>=60&&Listchoose<90)
        {
          Growthpoint tmp=(Growthpoint)Donkey.get (int(Listchoose-60));
          tmp.A++;
        }
        else 
        {
          Boundary tmp=(Boundary)Fish.get (int(Listchoose-90));
          tmp.A++;
        }
      }
      if (key == 'D' || key == 'd')
      {
        if (Listchoose<30)
        {
          attractor tmp=(attractor)Dog.get (int(Listchoose));
          tmp.A--;
        }
        else if (Listchoose>=30&&Listchoose<60)
        {
          earthpoint tmp=(earthpoint)Cat.get (int(Listchoose-30));
          tmp.A--;
        }
        else if(Listchoose>=60&&Listchoose<90)
        {
          Growthpoint tmp=(Growthpoint)Donkey.get (int(Listchoose-60));
          tmp.A--;
        }
        else 
        {
          Boundary tmp=(Boundary)Fish.get (int(Listchoose-90));
          tmp.A--;
        }
      }
    
      if (key == 'r' || key == 'R')
      {
        pcount=0;
        scount=0;
        physics = new VerletPhysics();
        physics.addBehavior(Gy);
        Punkt=new ArrayList();
        Linie=new ArrayList();
        Flaeche=new ArrayList();
        Setupgrowthpoint=true;
      }
    
    
    }
    
    VerletPhysics physics;
    GravityBehavior Gy=new GravityBehavior(Vec3D.Z_AXIS.scale(gravity));
    
    void initPhysics(){
      physics = new VerletPhysics();
      physics.addBehavior(Gy);
    }
    
    
    
    
    class threepoint {
      float h1,h2,h3,h4,h5,h6,h7;
      Vec3D A, B, C,D,E,F,G,CD,AD,BD,Np,Apos,Bpos,Cpos,Dpos,Epos,Fpos,Gpos,App,Bpp,Cpp,Dpp,Epp,Fpp,Gpp; 
      Vec2D A2d,B2d,C2d;
      boolean Que;
      int pc1,pc2,pc3;
      
      
      threepoint(Vec3D tempA, Vec3D tempB,Vec3D tempC)
      {
        A=tempA;
        B=tempB;
        C=tempC;
       // counterChilds=1;
        D=new  Vec3D(A.x/3+B.x/3+C.x/3,A.y/3+B.y/3+C.y/3,0);
        
      }
      void updateparticle()
      {
        Que=false;
        VerletParticle Ap=physics.particles.get(pc1);
        VerletParticle Bp=physics.particles.get(pc2);
        VerletParticle Cp=physics.particles.get(pc3);
        Apos=new Vec3D (Ap.x,Ap.y,Ap.z);
        Bpos=new Vec3D (Bp.x,Bp.y,Bp.z);
        Cpos=new Vec3D (Cp.x,Cp.y,Cp.z);
        Np=new Vec3D (-sin(Npa)*s13/2,cos(Npa)*s13/2,0);
        Dpos=new Vec3D (Apos.x/3+Bpos.x/3+Cpos.x/3,Apos.y/3+Bpos.y/3+Cpos.y/3,Apos.z/3+Bpos.z/3+Cpos.z/3);
        Vec3D ptemp=new Vec3D (Dpos.x,Dpos.y,0);
        whichone(ptemp);
        Boundary btemp=(Boundary)Fish.get (which);
        Np=new Vec3D (-sin(btemp.Npp)*btemp.R+btemp.A,cos(btemp.Npp)*btemp.R+btemp.B,0);
        
        float juli=ptemp.distanceTo(Np);
        float s=map(juli,0,btemp.R*2,s1,1);
        s=0.5*s;
        CD=Dpos.sub(Cpos);
        CD.scaleSelf(s);
        Epos=CD.add(Dpos);
        AD=Dpos.sub(Apos);
        AD.scaleSelf(s);
        Fpos=AD.add(Dpos);
        BD=Dpos.sub(Bpos);
        BD.scaleSelf(s);
        Gpos=BD.add(Dpos);
        A2d=new Vec2D (Apos.x,Apos.y);
        B2d=new Vec2D (Bpos.x,Bpos.y);
        C2d=new Vec2D (Cpos.x,Cpos.y);
        Polygon2D Thisone=new Polygon2D(A2d,B2d,C2d);
        E= new Vec3D(Epos.x,Epos.y,0);
        F= new Vec3D(Fpos.x,Fpos.y,0);
        G= new Vec3D(Gpos.x,Gpos.y,0);
        float Ed=E.distanceTo(Np);
        float Fd=F.distanceTo(Np);
        float Gd=G.distanceTo(Np);
        float tmp1=map(juli,0,btemp.R*2,0,1);
        float verdist=s2*(1-tmp1);
        Vec3D htemp=new Vec3D(0,0,verdist);
        Vec3D htempm=new Vec3D(0,0,-verdist);
        if(Ed<juli){
          Epos=Epos.add(htemp);
        }
        if(Ed>juli){
          Epos=Epos.add(htempm);
        }
        if(Epos.z<0)
        {
          Epos.z=0;
        }
        if(Fd<juli){
          Fpos=Fpos.add(htemp);
        }
        if(Fd>juli){
          Fpos=Fpos.add(htempm);
        }
        if(Fpos.z<0)
        {
          Fpos.z=0;
        }
        if(Gd<juli){
          Gpos=Gpos.add(htemp);
        }
        if(Gd>juli){
          Gpos=Gpos.add(htempm);
        }
        if(Gpos.z<0)
        {
          Gpos.z=0;
        }
        
        
      }
      void updatepos()
      {
        Que=false;
        fill(127,50);
        Hug (A.x,A.y);
        h1=h;
        Apos=new Vec3D(A.x,A.y,h1);
        Hug (B.x,B.y);
        h2=h;
        Bpos=new Vec3D(B.x,B.y,h2);
        Hug (C.x,C.y);
        h3=h;
        Cpos=new Vec3D(C.x,C.y,h3);
        Np=new Vec3D (-sin(Npa)*s13/2,cos(Npa)*s13/2,0);
        Hug (A.x/3+B.x/3+C.x/3,A.y/3+B.y/3+C.y/3);
        h4=h;
        D=new Vec3D (A.x/3+B.x/3+C.x/3,A.y/3+B.y/3+C.y/3,0);
        Dpos=new Vec3D(D.x,D.y,h4);
        Vec3D ptemp=new Vec3D (Dpos.x,Dpos.y,0);
        whichone(ptemp);
        Boundary btemp=(Boundary)Fish.get (which);
        Np=new Vec3D (-sin(btemp.Npp)*btemp.R+btemp.A,cos(btemp.Npp)*btemp.R+btemp.B,0);
        
        float juli=ptemp.distanceTo(Np);
        float s=map(juli,0,btemp.R*2,s1,1);
        s=0.5*s;
        CD=D.sub(C);
        CD.scaleSelf(s);
        E=CD.add(D);
        Hug (E.x,E.y);
        h5=h;
        Epos=new Vec3D(E.x,E.y,h5);
        AD=D.sub(A);
        AD.scaleSelf(s);
        F=AD.add(D);
        Hug (F.x,F.y);
        h6=h;
        Fpos=new Vec3D(F.x,F.y,h6);
        BD=D.sub(B);
        BD.scaleSelf(s);
        G=BD.add(D);
        Hug (G.x,G.y);
        h7=h;
        Gpos=new Vec3D(G.x,G.y,h7);
        A2d=new Vec2D (A.x,A.y);
        B2d=new Vec2D (B.x,B.y);
        C2d=new Vec2D (C.x,C.y);
        Polygon2D Thisone=new Polygon2D(A2d,B2d,C2d);
        float Ed=E.distanceTo(Np);
        float Fd=F.distanceTo(Np);
        float Gd=G.distanceTo(Np);
        float tmp1=map(juli,0,btemp.R*2,0,1);
        float verdist=s2*(1-tmp1);
        Vec3D htemp=new Vec3D(0,0,verdist);
        Vec3D htempm=new Vec3D(0,0,-verdist);
        if(Ed<juli){
          Epos=Epos.add(htemp);
        }
        if(Ed>juli){
          Epos=Epos.add(htempm);
        }
        if(Epos.z<0)
        {
          Epos.z=0;
        }
        if(Fd<juli){
          Fpos=Fpos.add(htemp);
        }
        if(Fd>juli){
          Fpos=Fpos.add(htempm);
        }
        if(Fpos.z<0)
        {
          Fpos.z=0;
        }
        if(Gd<juli){
          Gpos=Gpos.add(htemp);
        }
        if(Gd>juli){
          Gpos=Gpos.add(htempm);
        }
        if(Gpos.z<0)
        {
          Gpos.z=0;
        }
        
        for(int i=0;i<Cat.size();i=i+1){
          earthpoint b=(earthpoint)Cat.get(i);
          if (b.run)
          {
            Vec2D tmp=new Vec2D(b.A,b.B);
            if (Thisone.containsPoint( tmp )){
               //Dpos=new Vec3D(D.x,D.y,0);
               Epos=new Vec3D(E.x,E.y,h5/2);
               Fpos=new Vec3D(F.x,F.y,h6/2);
               Gpos=new Vec3D(G.x,G.y,h7/2);
               Que=true;
            }
          }
        }
    
      }
      
      void drawthreepoint()   
      {
        stroke(200);
        strokeWeight (1);
        fill(255);
        if(wireallow)
        {
        noFill();
        }
        if (!Que)
        {
          gfx.line(Epos,Dpos);
          gfx.line(Fpos,Dpos);
          gfx.line(Gpos,Dpos);
          beginShape();
          gfx.vertex(Apos);
          gfx.vertex(Epos);
          gfx.vertex(Bpos);
          gfx.vertex(Dpos);
          gfx.vertex(Apos);
          endShape();
          //////////AB
          beginShape();
          gfx.vertex(Cpos);
          gfx.vertex(Fpos);
          gfx.vertex(Bpos);
          gfx.vertex(Dpos);
          gfx.vertex(Cpos);
          endShape();
          /////////////BC
          beginShape();
          gfx.vertex(Cpos);
          gfx.vertex(Gpos);
          gfx.vertex(Apos);
          gfx.vertex(Dpos);
          gfx.vertex(Cpos);
          endShape();
          noFill();
          beginShape();
          stroke(100);
          gfx.vertex(Apos);
          gfx.vertex(Bpos);
          gfx.vertex(Cpos);
          gfx.vertex(Apos);
          endShape();
        }
        if(Que)
        {
          Vec3D D0=new Vec3D(D.x,D.y,D.z);
          beginShape();
          gfx.vertex(Apos);
          gfx.vertex(Epos);
          gfx.vertex(D0);
          gfx.vertex(Gpos);
          gfx.vertex(Apos);
          endShape();
          beginShape();
          gfx.vertex(Bpos);
          gfx.vertex(Epos);
          gfx.vertex(D0);
          gfx.vertex(Fpos);
          gfx.vertex(Bpos);
          endShape();
          beginShape();
          gfx.vertex(Cpos);
          gfx.vertex(Gpos);
          gfx.vertex(D0);
          gfx.vertex(Fpos);
          gfx.vertex(Cpos);
          endShape();
          gfx.line(Apos,Dpos);
          gfx.line(Bpos,Dpos);
          gfx.line(Cpos,Dpos);
        }
      }
      void sendmesh ()
      {
        Line3D segment;
        segment=new Line3D (Dpos,Apos);
        builder.createLattice(brush, segment, 1);
        segment=new Line3D (Dpos,Bpos);
        builder.createLattice(brush, segment, 1);
        segment=new Line3D (Dpos,Cpos);
        builder.createLattice(brush, segment, 1);
        segment=new Line3D (Apos,Epos);
        builder.createLattice(brush, segment, 1);
        segment=new Line3D (Bpos,Epos);
        builder.createLattice(brush, segment, 1);
        segment=new Line3D (Apos,Gpos);
        builder.createLattice(brush, segment, 1);
        segment=new Line3D (Cpos,Gpos);
        builder.createLattice(brush, segment, 1);
        segment=new Line3D (Bpos,Fpos);
        builder.createLattice(brush, segment, 1);
        segment=new Line3D (Cpos,Fpos);
        builder.createLattice(brush, segment, 1);
        if (Que){
          segment=new Line3D (D,Fpos);
          builder.createLattice(brush, segment, 1);
          segment=new Line3D (D,Epos);
          builder.createLattice(brush, segment, 1);
          segment=new Line3D (D,Gpos);
          builder.createLattice(brush, segment, 1);
          segment=new Line3D (D,E);
          builder.createLattice(brush, segment, 1);
          segment=new Line3D (D,G);
          builder.createLattice(brush, segment, 1);
          segment=new Line3D (D,F);
          builder.createLattice(brush, segment, 1);
        }
      }
    }
    
    
    
    
    class twopoint{
      Vec3D A, B;
      int counterChilds,sc;
      twopoint(Vec3D tempA, Vec3D tempB)
      {
    //    super(tempA,tempB);
        A=tempA;
        B=tempB;
        counterChilds=1;
        sc=scount;
      }
    
    }
    
    
    class onepoint extends Vec3D
    {
      Vec3D A; 
      int counterChilds=1,pc;
      onepoint(Vec3D tempA)
      {
        super(tempA);
        A=tempA;
        pc=pcount;
      }
    }
    
    
    
    import toxi.geom.*;
    import toxi.geom.mesh.*;
    import toxi.volume.*;
    import toxi.color.*;
    import toxi.processing.*;
    
     
    int VOXEL_RES=64;
    int VOXEL_STROKE_WEIGHT=7;
    int SPHERE_RES=8;
    int SMOOTH_ITER=6;
    ToxiclibsSupport gfx;
    WETriangleMesh mesh;
    int voxelRes = 300;
    AABB bounds3D;
    MeshLatticeBuilder builder;
    VolumetricSpace volume;
    VolumetricBrush brush;
     
    boolean isWireframe;
    void boundd()
    {
      bounds3D = new AABB();
    
      Vec3D c1=new Vec3D(75,75,50);
      Vec3D c2=new Vec3D(-75,-75,-50);
    
      
      bounds3D.growToContainPoint(c1);
      bounds3D.growToContainPoint(c2);
      
    }
    void setupStructure() 
    {
      mesh = new WETriangleMesh();
      Vec3D extent = bounds3D.getExtent();
      builder = new MeshLatticeBuilder(extent.scale(2),voxelRes, voxelRes, voxelRes/2, new FloatRange(1, 1));
      builder.setInputBounds(new AABB(bounds3D, extent.scale(1f)));
      volume = builder.getVolume();
      brush = new BoxBrush(volume, 0.5f);
      brush.setMode(VolumetricBrush.MODE_PEAK);
    }
    
    void voxelizemesh()
    {
      volume.closeSides();
      new HashIsoSurface(volume).computeSurfaceMesh(mesh, 1f);
      new LaplacianSmooth().filter(mesh, 10);
    }
    
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    Zhili Li

    Toy_for_architects2_0

    Add to Faves Me Likey@! 2
    You must login/register to add this sketch to your favorites.

    a further step from the 1.0version, growthprocess+hanging system, i tried to make things logic,thx for the toxic lib maker Karsten Schmitz. and i would like the have communications with all the guys who have taken a look at my project,hope u enjoy it.
    sory again for the suck work from P3D, plz download it and change it to Opengl, don forget to ply with full window.
    have fun!!!
    for clear video from this project plz go to
    https://vimeo.com/45273264
    for more clear fotos plz go to
    http://www.flickr.com/photos/80135466@N05/sets/72157630012913349/

    @zl_li

    You need to login/register to comment.