home *** CD-ROM | disk | FTP | other *** search
/ ANews 3 / AnewsCD3.iso / atari / GRAPHX / POV / 68030.060 / POV31G30 / POVRAY_3.1G / SCENES / ANIMATE / LIFE / LIFE.POV < prev    next >
Text File  |  1999-10-30  |  3KB  |  130 lines

  1. /*
  2. Life.Pov Celular autotomata life animation for POV-Ray 3.0
  3.    by JIm WIlliamson 100041,2563
  4.    using a character string to simulate arrays.
  5. Adapted for POV-Ray 3.1 using arrays by Chris Young
  6. */
  7.  
  8. camera {location 100*y  direction z*2.1  look_at <0,0,0>}
  9. light_source { <10,100,5> color rgb 1}
  10.  
  11. #declare LifeObject=sphere{<0,0,0>,0.49 no_shadow}
  12. #declare LifeTex=texture { pigment {rgb 1} }
  13.  
  14. #if (file_exists("lifedata.inc"))
  15.    #include "lifedata.inc"
  16. #else
  17.    #declare NumCols=60;
  18.    #declare NumRows=40;
  19.    #declare Gen    =0;
  20.    #declare Ratio=0.75;
  21.    #declare LifeGrid=array[NumRows][NumCols]
  22.    #declare LR=seed(554);
  23.  
  24.    // Initialize grid with random values
  25.    #declare Row     = 0;
  26.    #while(Row<NumRows)
  27.       #declare Column=0;
  28.       #while (Column<NumCols)
  29.          #if(rand(LR)>Ratio)
  30.             #declare LifeGrid[Row][Column]=1;
  31.          #else
  32.             #declare LifeGrid[Row][Column]=0;
  33.          #end
  34.          #declare Column=Column+1;
  35.       #end
  36.       #declare Row=Row+1;
  37.    #end
  38. #end
  39.  
  40. #declare NC2=-NumCols/2;
  41. #declare NR2=-NumRows/2;
  42.  
  43. // Display results
  44. #declare Row = 0;
  45. #while (Row < NumRows)
  46.    #declare Column = 0;
  47.    #while (Column < NumCols)
  48.          object {
  49.            LifeObject
  50.       #if (LifeGrid[Row][Column])
  51.            texture {LifeTex}
  52.       #else
  53.            pigment{rgb<1,0,0>}
  54.            scale .5
  55.       #end
  56.            translate<Column,0,Row>
  57.            translate<NC2,0,NR2>
  58.         }
  59.       #declare Column = Column + 1;
  60.    #end
  61.    #declare Row = Row + 1;
  62. #end
  63.  
  64. #debug concat("Generation ",str(Gen,3,0),"\n")
  65.  
  66. #declare Gen=Gen+1;
  67.  
  68. // Compute next generation
  69. #fopen LifeNext "lifedata.inc" write
  70.  
  71. #write (LifeNext, "#declare Gen=",str(Gen,4,0),";\n")
  72. #write (LifeNext, "#declare NumCols=",str(NumCols,4,0),";\n")
  73. #write (LifeNext, "#declare NumRows=",str(NumRows,4,0),";\n")
  74. #write (LifeNext, "#declare LifeGrid=array[NumRows][NumCols]\n")
  75.  
  76. #write (LifeNext, "{")
  77.  
  78. #declare Row = 0;
  79. #while (Row < NumRows)
  80.    #if (Row)
  81.       #write (LifeNext, ",\n")
  82.    #end
  83.    #write (LifeNext, "{")
  84.  
  85.    #declare Column = 0;
  86.    #while (Column < NumCols)
  87.       #if (Column)
  88.          #write (LifeNext, ",")
  89.       #end
  90.  
  91.       #declare Near = 0;
  92.       #declare YY = Row - 1;
  93.       #while (YY <= Row + 1)
  94.          #declare Y3=mod(YY+NumRows,NumRows);
  95.          #declare XX = Column - 1;
  96.          #while (XX <= Column + 1)
  97.             #declare X3=mod(XX+NumCols,NumCols);
  98.             #if ((XX=Column)&(YY=Row))
  99.             #else
  100.                #declare Near=Near+LifeGrid[Y3][X3];
  101.             #end
  102.             #declare XX = XX + 1;
  103.          #end
  104.          #declare YY = YY + 1;
  105.       #end
  106.       #if (LifeGrid[Row][Column])
  107.          #if((Near=2) | (Near=3))
  108.             #write (LifeNext, "1")
  109.          #else
  110.             #write (LifeNext, "0")
  111.          #end
  112.       #else
  113.          #if (Near=3)
  114.             #write (LifeNext, "1")
  115.          #else
  116.             #write (LifeNext, "0")
  117.          #end
  118.       #end
  119.       #declare Column = Column + 1;
  120.    #end
  121.    #declare Row = Row + 1;
  122.    #write (LifeNext, "}")
  123. #end
  124.  
  125. #write (LifeNext, "}\n")
  126.  
  127. #fclose LifeNext
  128.  
  129.  
  130.