• fullscreen
  • Attractor.pde
  • Bunch.pde
  • Pencil.pde
  • dm_10.pde
  • //A(ttractor)/////////////Simplest class to store the location of the attractors///
    //With this functionality this class even is not necessary, I keep it for further//
    //updates on code or remixes-refixes or whatever//^-^//////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////
    
    class Attractor {
     PVector l=new PVector(random(width),random(height));  //location
     PVector getL(){return l;}
    }
    
    //Bunch class//a class to pack all pencils together///
    //////////////////////////////////////////////////////
    
    class Bunch {
    
     Pencil[] pencils;
     
     float 
     factor;  
     int 
     cols,    
     rows;    
      
      //CONSTRUCTOR
      Bunch (int xg,int yg,float factor){
        cols=width/xg;
        rows=height/yg;
        pencils=new Pencil[cols*rows];
        for (int i=0;i<pencils.length;i++){  
          pencils[i]=new Pencil(new PVector(i%cols*xg,floor(i/cols)*yg));
        }
        this.factor=factor;
      }
      
      //METHODS
      //update is the method that resolves the forces influence. It has two methods:
        //first one//forces are related to distance but they act on the infinity of cosmic space
      void update(Attractor[] attractors){
        for(int i=0;i<pencils.length;i++){
          for (int j=0;j<attractors.length;j++){
            pencils[i].update(attractors[j].getL(),factor);
          }
        }  
      }  
      
        //second one//forces have a quite straight limit, beyond it the influence ends abruptly  
      void update(Attractor[] attractors,float maxDist){
        for(int i=0;i<pencils.length;i++){
          for (int j=0;j<attractors.length;j++){
            float d=PVector.dist(attractors[j].getL(),pencils[i].getL());
            if(d<maxDist){          
              pencils[i].update(attractors[j].getL(),factor);
            }
          }
        }  
      }  
      
      //display methods//very straight forward/////////////////////////////////////////////////
      void displayPoints(){
        for(int i=0;i<pencils.length;i++){
          pencils[i].display();
        }
      }
      
      void displayLines(){
        for(int i=0;i<rows;i++){
          beginShape();
          for(int j=0;j<cols;j++){
            int pos=(i*cols)+j;
            PVector current=pencils[pos].getL();
            vertex(current.x,current.y);  
          }
          endShape();
        }
      }  
    }
    
    
    
    
    
    //Pencil class//////////////Almost simplest particle class
    
    class Pencil {
      
      PVector l;  //location
      int p_hue;  //hue
     
      //CONSTRUCTOR
      Pencil (PVector l){this.l=l;}
     
      //METHODS 
      void display(){
        point(l.x,l.y);
      }
      
      //Main updating method 
      //Very straight-forward -- we calculate the vector that links force and particle and we scale it with
      //the inverse of the distance to make that force less powerful as the p goes further
      void update (PVector f,float sc){  
        PVector toF=PVector.sub(l,f);  //this is the vector that expulses the particle far from the force
        float dF=toF.mag();            //this is the magnitude of that vector: the distance 
        toF.normalize();               //we normalize force
        toF.mult(sc/dF);               //and scale it with an arbitrary factor plus the inverse of the distance
        l.add(toF);                    //we add it to location
      }
      
      //get&set
      PVector getL(){return l;}
      int getH(){return p_hue;}
      void setH(int hue_to_set){p_hue=hue_to_set;}
      
    }
    
    //drawing machine #10////Ale González////a(en)60rpm.tv/////Pubic Domain//
    //A bunch of discipled particles marching through a force field,/////////
    //Inspired by Marius Watz work///////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////
    
    Bunch bunch;            //Group of particles
    Attractor[] attractors; //Group of attractors
    int 
    NA=200,                 //Number of attractors
    CR=360,                 //colormode range 
    A=CR/10;                //alpha of stroke
    boolean 
    zzz=false,              //Sleeping boolean to toggle the loop
    displayingPoints=true,
    thereAreLimits=true;
    
    
    
    void setup(){
      //general settings
      size(900,450,P2D);   //P2D for a better performance (althoug the rendering is worse)
      colorMode(HSB,CR);
      background(#ffffff);
      smooth();
      stroke(#000000,A);
      strokeWeight(1.1);   //for a better rendering on P2D
      noFill(); 
      //object settings, we instantiate the particles with the dimensiones of the grid, 
      //and a factor to shift the forces acting on them
      bunch=new Bunch(5,5,20);   
      attractors=new Attractor[NA];
      for (int i=0;i<NA;i++){      
        attractors[i]=new Attractor(); 
      }
    }
    
    void draw(){
      if(!zzz){
        if(thereAreLimits){
          bunch.update(attractors,150);
        }else{
          bunch.update(attractors);
        }
      bunch.displayPoints();
      }
    }
    
    void mousePressed(){
      zzz=!zzz; 
    }
    
    void keyPressed(){
      switch(key){
       case('1'):
         thereAreLimits=true;
         setup();
         break; 
       case('2'):
         thereAreLimits=false;
         setup();
         break;
      }
    }
    
    
    
    

    code

    tweaks (1)

    about this sketch

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

    license

    advertisement

    ale plus+

    drawingMachine_10

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

    A bunch of discipled particles marching through a force field. Takes as source of inspiration Marius Watz's 'Grid Distortion'.
    Interaction:
    Keys '1' and '2' to reset the drawing, using limits or not (default '1', limits on).
    Click to halt the loop.
    Inside there's another displaying method, using shapes instead of points.

    awesome
    Eduardo Obieta
    22 Mar 2012
    Organico :)
    Raven Kwok plus+
    12 Jan 2013
    This is so elegant !
    Adam Lastowka
    11 Apr 2013
    Whoa!
    Adam Lastowka
    11 Apr 2013
    Whoa!
    ale plus+
    11 Apr 2013
    Glad you like it!
    ; )
    Marius Watz plus+
    17 Aug 2013
    Very nice. Happy to see you were inspired by my grid experiments, I like the organic distribution of "shaded" and empty spaces.

    This actually reminds me of a piece by Lia (different algo, it just feels similar somehow): http://www.liaworks.com/theprojects/proximityofneeds/
    ale plus+
    19 Aug 2013
    I have been very inspired by all your work, Marius. You're a great artist. ; )
    Pd: Thanks for the reference. Nice work! Lia is also very inspiring... : )
    You need to login/register to comment.