Part III

 
Sol LeWitt died



Image from nytimes.com


Image from http://www.artline.com/

 

Reference on Cellular Automata


Stephen Wolfram

 

Understanding pixel operation in Processing
Row by row animation with pixels
1D Cellular Automata
Single pixel as initial condition
Random pixels as initial condition
2D Cellular Automata
The Game of Life


It is developed by John Conway. The Game of Life is a 2D cellular automata with the following rules to generate the new state.

class CA {
   int [][][] buffer;
   int row, col;
   int curr, next;
   int w, h;
   boolean run;
   CA(int _r, int _c) {
      row = _r;
      col = _c;
      buffer = new int[2][_r][_c]; 
      curr = 0;
      next = 1;
      w = width/col;
      h = height/row;
      run = true;
      init();
   }
   void init() {
      for (int r=0;r<row;r++) {
         for (int c=0;c<col;c++) {
            buffer[curr][r][c] = int(random(2));
            buffer[next][r][c] = buffer[curr][r][c];
         }
      }
   }
   void update() {
      if (run) {
         int temp = curr;
         curr = next;
         next = temp;
         for (int r=0;r<row;r++) {
            for (int c=0;c<col;c++) {
               buffer[next][r][c] = rules(r,c);
            }
         }
      }
      render();
   }
   void render() {
      for (int r=0;r<row;r++) {
         for (int c=0;c<col;c++) {
            if (buffer[next][r][c]==1) {
               fill(255,240,0);
            } else {
               fill(0);
            }
            rect(c*w,r*h,w-1,h-1);
         }
      }
   }
   int rules(int _r, int _c) {
      int res = buffer[curr][_r][_c];
      int up = (_r-1+row) % row;
      int left = (_c-1+col) % col;
      int down = (_r+1) % row;
      int right = (_c+1) % col;
      int num = 0;

      if (buffer[curr][up][left]==1)    num++;
      if (buffer[curr][up][_c]==1)      num++;
      if (buffer[curr][up][right]==1)   num++;
      if (buffer[curr][_r][left]==1)    num++;
      if (buffer[curr][_r][right]==1)   num++;
      if (buffer[curr][down][left]==1)  num++;
      if (buffer[curr][down][_c]==1)    num++;
      if (buffer[curr][down][right]==1) num++;
      if (buffer[curr][_r][_c]==1 && num<2) {
         res = 0;
      } 
       else if (buffer[curr][_r][_c]==1 && num>3) {
         res = 0;
      } 
       else if (buffer[curr][_r][_c]==1 && (num==2 || num==3)) {
         res = 1;
      } 
       else if (buffer[curr][_r][_c]==0 && num==3) {
         res = 1;
      }
      return res;
   }
   void toggle() {
      run = !run;
   }
}           

To view this content, you need to install Java from java.com

 

Variations

To view this content, you need to install Java from java.com

 

Reference