• fullscreen
  • agent.pde
  • agents_heightmap.pde
  • class Agent{
      PVector pos, vel, dr;
      color c;
      int searchDist;
      float maxVal=255;
    
      Agent(int _x, int _y){
        pos=new PVector(_x,_y);  
        vel=new PVector(0,0);
        c=color(random(255),random(255),random(255));
        searchDist=2;//how much an agent knows about its surroundings
      }
    
    
      void move(){
        PVector dir = PVector.sub(brightPt(),pos);
        vel.add(dir);
        //PVector jump= new PVector(random(-0.1,0.1),random(-0.1,0.1));//jump a little to get out of local minima   
        // vel.add(jump);
        vel.mult(0.9);
        vel.limit(1);  
        pos.add(vel);  
      }
    
      void display(){
        set((int)pos.x,(int)pos.y,c);
      }
    
      PVector brightPt(){//search for darkest pixel around within 'searchDist' distance    
        PVector bPt=new PVector(pos.x,pos.y);
        for(int x=(int)pos.x-searchDist;x<=(int)pos.x+searchDist;x++){
          for(int y=(int)pos.y-searchDist;y<=(int)pos.y+searchDist;y++){
            float currVal=brightness(env.get(x,y));
            if(currVal<maxVal){
              maxVal=currVal;
              bPt=new PVector(x,y);       
            }
          }     
        }
        return bPt;
      }
    }
    
    
    
    
    
    //by echoechonoisenoise
    //for BrainCityLab 2010
    
    ArrayList agents;
    PImage env;
    int agentsAmount=25000;
    
    void setup(){
      size(800,600,P2D);
      noStroke();
      env=loadImage("map.png");
      agents=new ArrayList();
    
      for(int i=0;i<agentsAmount;i++){
        agents.add(new Agent(round(random(10,width-10)),round(random(10,height-10))));
      }
    }
    
    void draw(){
      image(env,0,0);
      for(int i=0;i<agents.size();i++){
        Agent a =(Agent)agents.get(i);
        a.move();
        a.display();
      }  
    }
    
    void mouseDragged(){
       for(int i=0;i<5;i++){
        agents.add(new Agent(round(mouseX+random(-1,1)),round(mouseY+random(-1,1))));
      }  
    }
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement

    echoechonoisenoise

    agents + heightmap

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

    agents searching darkest places on the map.

    You need to login/register to comment.