POV-Ray : Newsgroups : povray.binaries.animations : Conway Server Time
28 Mar 2024 13:16:55 EDT (-0400)
  Conway (Message 1 to 6 of 6)  
From: ingo
Subject: Conway
Date: 22 Jun 2022 05:35:00
Message: <web.62b2e11bfc14546617bac71e8ffb8ce3@news.povray.org>
Just a Game of Life. I wanted to see the transitions in state instead of just
flipping cells.

ingo

---%<---%<---%<---

// Persistence of Vision Ray Tracer Scene Description File
// File: conway.pov
// Vers: 3.7
// Desc: Game of Life, "slow version" to show the transistions
// Date: 2022/06/16
// Auth: Ingo Janssen
//
// cmd: +am2 +a0.5 +w640 +h360 +kff3000
// ffmpeg -r 30 -f image2 -s 640x360 -i conway%04d.png -vcodec libx265 -crf 30
-preset veryslow -pix_fmt yuv420p conway.mp4

#version 3.7;
#include "rand.inc"
#include "math.inc"

global_settings{ assumed_gamma 1.0 }
#default{ finish{ ambient 0.1 diffuse 0.9 }}


#declare Stream = seed(777);

#declare _CAstate_current = 0;
#declare _CAstate_last = 1;
// variables
#declare _CAdead = 0;
#declare _CAlive = 1;


/*====
CAinit(SizeX, SizeY): Initialize the two dimensional grid for the Game of life.
It will contain te current state and the last state of each cell in the grid.

SizeX, SizeY: the grid dimensions
*/
#macro CAinit(SizeX, SizeY)
  #local CAgrid = array[SizeX][SizeY];
  #for(i,0,SizeY-1)
    #for(j,0,SizeX-1)
      #local CAgrid[j][i] = array[2]{0,0};
    #end
  #end
  CAgrid
#end

/*====
CArndState(CAgrid): Randomize the grid's current state, fill with 1 & 0's

CAgrid: Two dimensional array that is the grid.
*/
#macro CArndState(CAgrid)
  #for(i, 0, dimension_size(CAgrid, 2) - 1)
    #for(j, 0, dimension_size(CAgrid, 1) - 1)
      #local rndVal = Prob(0.5, Stream);
      #local CAgrid[j][i][_CAstate_current] = rndVal;
    #end
  #end
#end

/*====
CAwrite(CAgrid, Path): writes the current and last state of the grid to file

CAgrid: Two dimensional array that is the grid.
Path: path/file name to write the file to.
*/
#macro CAwrite(CAgrid, Path)
  #local SizeX =  dimension_size(CAgrid,1);
  #local SizeY =  dimension_size(CAgrid,2);
  #local Vals = "";
  #for(i, 0, SizeY - 1)
    #for(j, 0, SizeX - 1)
      #local Vals = concat(Vals,
        str(CAgrid[j][i][_CAstate_current],0,0),",",
        str(CAgrid[j][i][_CAstate_last],0,0),","
      );
    #end
    #local Vals = concat(Vals, "\n");
  #end
  #fopen CAFile Path write
    #write (CAFile SizeX "," SizeY "\n")
    #write (CAFile Vals)
  #fclose CAFile
#end

/*====
CAread(CAgrid, Path): reads the current and last state of the grid from file
into the grid

CAgrid: Two dimensional array that is the grid and holds the states
Path: path/file name to write the file to.
*/
#macro CAread(CAgrid, Path)
  #local SizeX = 0;
  #local SizeY = 0;
  #fopen CAFile Path read
    #read(CAFile SizeX, SizeY)
    #for(i, 0, SizeY - 1)
      #for(j, 0, SizeX - 1)
        #read(CAFile
          CAgrid[j][i][_CAstate_current],
          CAgrid[j][i][_CAstate_last],
        )
      #end
    #end
  #fclose CAFile
#end


#macro CAdebug(CAgrid)
  #debug concat("Frame number: ",str(frame_number,0,0),"\n")
  #debug "Current state:\n"
  #for(i, 0, dimension_size(CAgrid, 2) - 1)
    #for(j, 0, dimension_size(CAgrid, 1) - 1)
      #debug concat(str(CAgrid[j][i][_CAstate_current],0,0)," ")
    #end
    #debug "\n"
  #end
  #debug "Last state:\n"
  #for(i, 0, dimension_size(CAgrid, 2) - 1)
    #for(j, 0, dimension_size(CAgrid, 1) - 1)
      #debug concat(str(CAgrid[j][i][_CAstate_last],0,0)," ")
    #end
    #debug "\n"
  #end
  #debug "\n"
#end


#declare RollOver = function(ModAB, B){
  select(ModAB, B + ModAB, ModAB)
}//#debug concat(str(RollOver(mod(-0.1, 3), 3),0,-1),"\n")

#macro CAgetNeighbours(CAgrid, CurrentCell)
  #local SizeX = dimension_size(CAgrid, 1);
  #local SizeY = dimension_size(CAgrid, 2);
  #local Sum = 0;
  #for(i, CurrentCell.y-1, CurrentCell.y+1)
    #local I = RollOver(mod(i,SizeY), SizeY);
    #for(j, CurrentCell.x-1, CurrentCell.x+1)
      #local J = RollOver(mod(j,SizeX), SizeX);
      #local Sum = CAgrid[J][I][_CAstate_last] + Sum;
    #end
  #end
  #local Sum = Sum - CAgrid[CurrentCell.x][CurrentCell.y][_CAstate_last];
  Sum
#end


#macro CArulerun(CAgrid)
  #local SizeX = dimension_size(CAgrid,1);
  #local SizeY = dimension_size(CAgrid,2);
  #for(i, 0, SizeY - 1)
    #for(j, 0, SizeX - 1)
      #local CAgrid[j][i][_CAstate_last] = CAgrid[j][i][_CAstate_current];
    #end
  #end
  #for(i, 0, SizeY - 1)
    #for(j, 0, SizeX - 1)
      #local CurrentCell = <j,i>;
      #local CurrentValue = CAgrid[j][i][_CAstate_last];
      #local Neighbour = CAgetNeighbours(CAgrid, CurrentCell);
      #if(CurrentValue = 1 & Neighbour < 2)
        #local CAgrid[j][i][_CAstate_current] = 0;
      #elseif(CurrentValue = 1 & Neighbour > 3)
        #local CAgrid[j][i][_CAstate_current] = 0;
      #elseif(CurrentValue = 0 & Neighbour = 3)
        #local CAgrid[j][i][_CAstate_current] = 1;
      #end
    #end
  #end
#end


#macro CAobject(CAgrid, Frames)
  #local Frame = mod(frame_number, Frames);
  #local Half = Frames/2;
  #debug concat(str(Frame,0,-1)," , ",str(Half,0,-1) ,"\n")
  union {
    #if(Frame>Half)
      #for(i, 0, dimension_size(CAgrid, 2) - 1)
        #for(j, 0, dimension_size(CAgrid, 1) - 1)
          #if(CAgrid[j][i][_CAstate_current] = 1)
            sphere{<j,i,0> 0.5 pigment {rgb 1}}
          #end
        #end
      #end
    #elseif(Frame <= Half)
      #for(i, 0, dimension_size(CAgrid, 2) - 1)
        #for(j, 0, dimension_size(CAgrid, 1) - 1)
          #if(CAgrid[j][i][_CAstate_current] != CAgrid[j][i][_CAstate_last])
            #if (CAgrid[j][i][_CAstate_current] = 1)
              sphere{<j,i,0> adj_range2(Frame,0,Half,0,0.5) pigment {rgb 1}}
            #else
              sphere{<j,i,0> adj_range2(Frame,0,Half,0.5,0) pigment {rgb 1}}
            #end
          #elseif(
            CAgrid[j][i][_CAstate_current] = CAgrid[j][i][_CAstate_last]
            & CAgrid[j][i][_CAstate_current] = 1
          )
            sphere{<j,i,0> 0.5 pigment {rgb 1}}
          #end
        #end
      #end
    #end
  }
#end


#declare TempFn = "conway.arr" //ramdisc
#declare Frames = 20;

#declare SizeX = 48;
#declare SizeY = 27;
#declare Conway = CAinit(SizeX, SizeY);
#if(file_exists(TempFn))
  CAread(Conway, TempFn)
#else
  CArndState(Conway)
#end
#if(mod(frame_number, Frames) = 0 & frame_number > 1)
  CArulerun(Conway)
  CAwrite(Conway, TempFn)
#end
//CAdebug(Conway)
object{CAobject(Conway, Frames)}

camera {
  angle 55
  location  <(SizeX/2)-0.5,(SizeY/2)-0.5, -50>
  look_at   <(SizeX/2)-0.5,(SizeY/2)-0.5, 0>
  right     x*image_width/image_height
}
light_source{
  <SizeX, SizeY, -2000>, rgb 1
}


Post a reply to this message


Attachments:
Download 'conway.mp4.dat' (2243 KB)

From: jr
Subject: Re: Conway
Date: 22 Jun 2022 16:05:00
Message: <web.62b37544def97904d6bf93276cde94f1@news.povray.org>
hi,

"ingo" <nomail@nomail> wrote:
> Just a Game of Life. ...

looking good, until frame #21.  :-)

File '/tmp/conway.arr' line 2: Parse Error: Expected 'float, vector, or string
 literal', ,  found instead
Fatal error in parser: Cannot parse input.
Render failed

same error/frame for 3.7.0.8 and beta.2.  no idea what the problem is, the file
looks kosher.


regards, jr.


Post a reply to this message

From: jr
Subject: Re: Conway
Date: 23 Jun 2022 06:00:00
Message: <web.62b4392ddef97904d6bf93276cde94f1@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:
> "ingo" <nomail@nomail> wrote:
> > Just a Game of Life. ...
> ...
> File '/tmp/conway.arr' line 2: Parse Error: Expected 'float, vector, or string
>  literal', ,  found instead
> Fatal error in parser: Cannot parse input.
>
> same error/frame for 3.7.0.8 and beta.2.  no idea what the problem is, the file
> looks kosher.

on closer examination, there was no comma after the 2nd value of the first line,
edited the 'CAwrite()' macro to add the comma with the newline:
    #write (CAFile SizeX "," SizeY ",\n")

(now will try to find time to actually look at the code. :-))


regards, jr.


Post a reply to this message

From: ingo
Subject: Re: Conway
Date: 23 Jun 2022 09:58:10
Message: <XnsAEBFA2727B6BCseed7@news.povray.org>
in news:web.62b4392ddef97904d6bf93276cde94f1@news.povray.org jr wrote:

> newline: 
>     #write (CAFile SizeX "," SizeY ",\n")
> 
> 
Fixed that. Thanks. Strange that I didn't trip over it.


-- 
https://ingoogni.nl


Post a reply to this message

From: ingo
Subject: Re: Conway
Date: 23 Jun 2022 10:07:45
Message: <XnsAEBFA41359E95seed7@news.povray.org>
in news:XnsAEBFA2727B6BCseed7@news.povray.org ingo wrote:

> Strange that I didn't trip over it.

seems to be 3.7.0 vs something newer, after a quick test (win10). The 
older one seems a bit more permissive.

ingo

-- 
https://ingoogni.nl


Post a reply to this message

From: jr
Subject: Re: Conway
Date: 24 Jun 2022 01:30:00
Message: <web.62b54aa3def97904d6bf93276cde94f1@news.povray.org>
hi,

ingo <ing### [at] tagpovrayorg> wrote:
> seems to be 3.7.0 vs something newer, after a quick test (win10). The
> older one seems a bit more permissive.

the .. permissiveness seems to exist on MS Windows only.  on Slackware Linux all
installed (3.7.0.8, 3.7.1-rc.1, 3.8.0-alpha.9945627 and betas) fail on the same
frame (#21); I cannot fathom why the error doesn't occur on the first read.


regards, jr.


Post a reply to this message

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