POV-Ray : Newsgroups : povray.text.scene-files : Game of Life implementation Server Time
1 Jun 2024 14:57:47 EDT (-0400)
  Game of Life implementation (Message 1 to 9 of 9)  
From: SeeSchloss
Subject: Game of Life implementation
Date: 6 Sep 2004 16:27:22
Message: <pan.2004.09.06.20.27.28.246600@seeschloss.org>
If anybody is interested, here's an implementation of a cellular
automaton, Conway's Game of Life, with POV's preprocessing language.

If special_pattern is true, the original pattern is taken from the file
specified by INIT (which must be the same size as the world), with white
pixels as dead cells and black pixels as living cells. If special_pattern
is false, then the initial cells are placed randomly (using seed SEED).

That's all, I hope Pan won't wrap my code, and if you have any question,
ask  :)

////////////////////////////

#declare cell_thickness = 0.125;

#declare HEIGHT = 30;
#declare WIDTH  = 30;

#declare SEED   = 1792;
#declare special_pattern = yes;

#declare STEPS  = 100;

#declare INIT="init.png"

////////////////////////////

#declare cell = box
                  {
                  <-0.5, 0.0, -0.5>
                  < 0.5, cell_thickness, 0.5>
                  texture
                    {
                    pigment
                      {
                      colour Yellow
                      }
                    }
                  }

#declare init_pattern = function
                          {
                          pattern
                            {
                            image_pattern
                              {
                              png INIT
                              }
                            }
                          }

////////////////////////////

#macro rnd (d)
  #declare dec = d - int (d);
  #if (dec < 0.5)
    #declare ret = int (d);
  #else
    #declare ret = int (d) + 1;
  #end
  ret;
#end

#macro evolve ()  // computes the next state of each cell
  #declare new_world = world;
  #declare i=1;
  #while (i <= HEIGHT)
    #declare j=1;
    #while (j <= WIDTH)
      #declare somme =         world[i  ][j+1];
      #declare somme = somme + world[i  ][j-1];
      #declare somme = somme + world[i+1][j-1];
      #declare somme = somme + world[i+1][j  ];
      #declare somme = somme + world[i+1][j+1];
      #declare somme = somme + world[i-1][j-1];
      #declare somme = somme + world[i-1][j  ];
      #declare somme = somme + world[i-1][j+1];
      #if (world[i][j] = 0)
        #if (somme = 3)
          #declare new_world[i][j] = 1;
        #end
      #else
        #if (somme != 2 & somme != 3)
          #declare new_world[i][j] = 0;
        #end
      #end
      #declare j=j+1;
    #end
  #declare i=i+1;
  #end
  #declare world = new_world;
#end

#macro show (level)
  #declare i=0;
  #while (i <= HEIGHT)
    #declare j=0;
    #while (j <= WIDTH)
      #if (world[i][j])
        object
          {
          cell
          translate <i-(HEIGHT/2), level*cell_thickness, j-(WIDTH/2)>
          texture
            {
            pigment
              {
              #if (odd (STEP))
                rgbft <STEP/STEPS/2, 1, STEP/STEPS, 0.0, 0.0>
              #else
                rgbft <1, STEP/STEPS/2, STEP/STEPS, 0.0, 0.0>
              #end
              }
            normal
              {
              bozo
              }
            finish
              {
              reflection 0.25
              }
            }
          }
      #end
      #declare j=j+1;
    #end
    #declare i=i+1;
  #end
#end

#macro init_world (empty)  // initialises the world, if (empty != 0), no cell is
placed
  #declare world  = array[HEIGHT+2];
  #declare i=0;         
  #while (i <= HEIGHT+1)
    #declare j=0;
    #declare world[i] = array[WIDTH+2];
    #while (j <= WIDTH+1)
      #if (i != 0 & i != HEIGHT+1)
        #if (j != 0 & j != WIDTH+1)
          #if (empty)
            #declare world[i][j] = 0;
          #else
            #declare world[i][j] = rnd (rand (germe) - 0.33);
            #end
        #else
          #declare world[i][j] = 0;
        #end
      #else
        #declare world[i][j] = 0;
      #end
      #declare j=j+1;
    #end
    #declare i=i+1;
  #end
#end

////////////////////////////

#declare germe = seed (SEED);

init_world (special_pattern)

#if (special_pattern)
  #declare i = 0;
  #while (i < HEIGHT)
    #declare j = 0;
    #while (j < WIDTH)
      #declare world[i][j] = -init_pattern ((i+0.5)/HEIGHT, (j+0.5)/WIDTH, 0) + 1;
      #declare j = j + 1;
    #end
    #declare i = i + 1;
  #end
#end

#declare STEP=0;
#while (STEP < STEPS)
  #debug "Placing level "
  #debug str (STEP+1, -(log (STEPS) + 1), 0)
  #debug "....... "
  union
    {
    show (STEP)
    rotate <0, 130, 0>
    }
  #debug "finished\nComputing next state... " evolve () #debug
  "finished\n"
  #declare STEP=STEP+1;
#end

////////////////////////////


Post a reply to this message

From: Josh
Subject: Re: Game of Life implementation
Date: 8 Sep 2004 09:07:02
Message: <413f03f6@news.povray.org>
Disapointed :-(     "odd" is undefined.  I'm going to cry, sniff...


Post a reply to this message

From: Dave VanHorn
Subject: Re: Game of Life implementation
Date: 8 Sep 2004 10:11:48
Message: <413f1324$1@news.povray.org>
> Disapointed :-(     "odd" is undefined.  I'm going to cry, sniff...

Same problem here, on POV 3.6

-- 
KC6ETE  Dave's Engineering Page, www.dvanhorn.org
Microcontroller Consultant, specializing in Atmel AVR


Post a reply to this message

From: Rangifer
Subject: Re: Game of Life implementation
Date: 8 Sep 2004 13:01:11
Message: <413f3ad7$1@news.povray.org>
Josh wrote:

> Disapointed :-(     "odd" is undefined.  I'm going to cry, sniff...
> 
> 
#include "math.inc"


Post a reply to this message

From: Dave VanHorn
Subject: Re: Game of Life implementation
Date: 8 Sep 2004 20:41:41
Message: <413fa6c5$1@news.povray.org>
> #include "math.inc"

That helps!

-- 
KC6ETE  Dave's Engineering Page, www.dvanhorn.org
Microcontroller Consultant, specializing in Atmel AVR


Post a reply to this message

From: SeeSchloss
Subject: Re: Game of Life implementation
Date: 9 Sep 2004 03:12:15
Message: <pan.2004.09.09.07.12.10.997304@seeschloss.org>
On Wed, 08 Sep 2004 14:07:02 +0100, Josh wrote:

> Disapointed :-(     "odd" is undefined.  I'm going to cry, sniff...

Sorry for that... I forgot the includes section. "math.inc" was the only
one really needed I think. (Anyway this odd() is only used to alternate
colours between levels).


Post a reply to this message

From: povray
Subject: Re: Game of Life implementation
Date: 9 Sep 2004 19:09:38
Message: <43d1k09vqcg52id1oj9s7e71p1k1voldcj@4ax.com>
On Wed, 08 Sep 2004 20:01:09 +0300, Rangifer
<rei### [at] rocketmailcom> wrote:

>Josh wrote:
>
>> Disapointed :-(     "odd" is undefined.  I'm going to cry, sniff...
>> 

Glad it is not just me.

>> 
>#include "math.inc"

Doops.  It never occured to me to do that.
I wrote my own "odd" macro instead.  :D


Post a reply to this message

From: povray
Subject: Re: Game of Life implementation
Date: 11 Sep 2004 00:21:12
Message: <hqq4k09ui910a8imlhk5pbjnudgfvg83q1@4ax.com>
On Mon, 06 Sep 2004 22:27:32 +0200, SeeSchloss
<adr### [at] seeschlossorg> wrote:

>If anybody is interested, here's an implementation of a cellular
>automaton, Conway's Game of Life, with POV's preprocessing language.
>

I am having fun with this little .pov
script you wrote.  :D  Tweaked some
things, used two gradients instead of all
the color calculations.

If you set one of the colors to a pale
yellow, it looks like you've got many
post-its floating in the picture  :D

Weeee!  Thanks for posting it.


Post a reply to this message

From: SeeSchloss
Subject: Re: Game of Life implementation
Date: 12 Sep 2004 13:36:56
Message: <pan.2004.09.12.17.36.58.311864@seeschloss.org>
On Fri, 10 Sep 2004 23:08:00 -0400, povray wrote:

> I am having fun with this little .pov script you wrote.  :D  Tweaked some
> things, used two gradients instead of all the color calculations.
> 
> If you set one of the colors to a pale yellow, it looks like you've got
> many post-its floating in the picture  :D
> 
> Weeee!  Thanks for posting it.

Thank you, I'm glad someone likes it :)


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.