• fullscreen
  • schelling01.pde
  • //by echoechonoisenoise
    //for brainCityLab 2010
    float [][] cell;
    
    void setup(){
      size(800,600,P2D);
      colorMode(RGB,1);
      cell=new float[width][height];
    
      for(int x=0;x<width;x++){
        for(int y=0;y<height;y++){
          cell[x][y]=random(1);
        }  
      }  
    }
    
    void draw(){
    
      for(int x=0;x<width;x++){
        for(int y=0;y<height;y++){
          set(x,y,color(cell[x][y]));
          if(neighbors(x,y)>4){
            cell[x][y]+=0.01;
          }
          if(neighbors(x,y)<4){
            cell[x][y]-=0.01;
          }
        }  
      } 
    }
    
    
    float neighbors(int x, int y){
      float value;
      if(x>0&&x<width-1&&y>0&&y<height-1){
        value=
          cell[x+1][y]+
          cell[x+1][y-1]+
          cell[x+1][y+1]+
          cell[x][y+1]+
          cell[x][y-1]+
          cell[x-1][y+1]+
          cell[x-1][y]+
          cell[x-1][y-1];
      }
      else{
        value=4;  
    
      }
      return value;
    }
    
    void mouseDragged(){
      for(int i=mouseX-30;i<mouseX+30;i++){
        for(int j=mouseY-30;j<mouseY+30;j++){
          if(dist(mouseX,mouseY,i,j)<30)cell[i][j]=random(1);
        }
      }
    }
    
    

    code

    tweaks (0)

    about this sketch

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

    license

    advertisement


    echoechonoisenoise

    segregation

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

    segregation model by Thomas Schelling, 1971.
    small local preference leads to stable global segregation pattern.
    use mouse to randomize cells around the cursor.

    You need to login/register to comment.