2009年7月9日 星期四

再思作品的概念


+ 基於Game of life而來的三項規則,使用LED所產生的光暗效果,做出豐富的圖案。

+ 用「實物」去表現,加強觀眾對“活”的感覺。




Game of Life 的規則


Source: http://www.math.com/students/wonders/life/life.html

用Arduino寫成的Game of Life程式如下:

void  gameOfLife()
{
  for(int i=0; i<49;>
  {
    int thisLED = markLED[1][i];
    
    int y = i / 7;
    int x = i - y * 7;     

    int up = i - 7;
    int down = i + 7;   
    int left = i - 1;
    int right = i + 1;
    int n1 = markLED[1][up];
    int n2 = markLED[1][down];
    int n3 = markLED[1][left];
    int n4 = markLED[1][right];

    int leftUpCorner = i - 7 - 1;
    int rightUpCorner = i - 7 + 1;
    int leftDownCorner = i + 7 - 1;
    int rightDownCorner = i + 7 + 1;
    int n5 = markLED[1][leftUpCorner];
    int n6 = markLED[1][rightUpCorner];
    int n7 = markLED[1][leftDownCorner];
    int n8 = markLED[1][rightDownCorner];

    if (y == 0) n1 = n5 = n6 = 0;
    if (y == 6) n2 = n7 = n8 = 0;
    if (x == 0) n3 = n5 = n7 = 0;
    if (x == 6) n4 = n6 = n8 = 0;
 
    int numNeibr = n1 + n2 + n3 + n4 + n5 + n6 + n7 + n8;

    if (thisLED == 0)  // Check Dead Cell
    {
      if (numNeibr == 3)
      {
        lc.setLed(0, y, x, true);
        markLED[0][x + y * 7] = 1;
      }
    }

    if (thisLED == 1)  // Check Live Cell
    {
      if (numNeibr <> 3) // die
      {
        lc.setLed(0, y, x, false);
        markLED[0][x + y * 7] = 0;
      } 
      if (numNeibr == 2 || numNeibr == 3) // live
      {
        lc.setLed(0, y, x, true);
        markLED[0][x + y * 7] = 1;
      }
    }
  }
}

(以上只是程式的一部分)

將這個程式upload到Arduino Board,可以使LED產生如同Game of Life的效果。