POV-Ray : Newsgroups : povray.binaries.images : Ripple Tank Sim : Re: Ripple Tank Sim Server Time
31 Jul 2024 22:17:59 EDT (-0400)
  Re: Ripple Tank Sim  
From: clipka
Date: 18 Aug 2009 12:49:39
Message: <4a8adba3$1@news.povray.org>
scott schrieb:
> never thought of the GoL on a GPU, should be easy to implement.

I bet. If it can be done in POV-Ray with textures only...

Here's the full POV-Ray SDL code for a GoL sim starting with a random 
pattern - the only non-linearity in control flow is the #if to care for 
first-frame initialization.

The world is toroidal, though this can be chaned by enabling the "once" 
keyword in the definition of PgNext.

As an interesting side note, the sim does /not/ store the end result of 
each generation, but interim results: The status of the cell itself, 
combined with a count of the surrounding live cells. This allows easy 
use of a color_map for the conditionals.

(The code could be made shorter by using macros, but I reckon this would 
be counter-productive for parsing speed.)

--------------------------------------

// +W100 +H100 +KFI1 +KFF9999 +FE

#version 3.6;

global_settings {
   assumed_gamma 1.0
   ambient_light 1.0
   max_trace_level 15
}

camera {
   orthographic
   location <0,0,100>
   look_at  <0,0,0>
   right   -1*x
   up       1*y
}



default {
   finish { ambient 1.0 diffuse 0.0 }
}

// ----------------------------------------

#local FrameDigits  = int(log(final_frame)) + 1;
#local NumLayers    = 9;
#local Delta        = 1/max(image_width,image_height);

#local NeighborFactor   = 0.05;
#local CellFactor       = 0.50;

#local EPSILON          = 1e-6;

#if (frame_number = 1)
   #local PgNext = pigment { bozo color_map { [ 0.499 rgb 0 ] [ 0.501 
rgb 1 ] } scale Delta }
#else
   #local PgNext = pigment {
     image_pattern { concat("Life", str(frame_number-1,-FrameDigits,0)) 
/*once*/ }
     color_map {
       // dead cell
       [ 0*CellFactor + 2.5*NeighborFactor -EPSILON  rgb 0 ]
       [ 0*CellFactor + 2.5*NeighborFactor +EPSILON  rgb 1 ]
       [ 0*CellFactor + 3.5*NeighborFactor -EPSILON  rgb 1 ]
       [ 0*CellFactor + 3.5*NeighborFactor +EPSILON  rgb 0 ]
       // live cell
       [ 1*CellFactor + 1.5*NeighborFactor -EPSILON  rgb 0 ]
       [ 1*CellFactor + 1.5*NeighborFactor +EPSILON  rgb 1 ]
       [ 1*CellFactor + 3.5*NeighborFactor -EPSILON  rgb 1 ]
       [ 1*CellFactor + 3.5*NeighborFactor +EPSILON  rgb 0 ]
     }
     translate -<0.5,0.5,0>
   }
#end

#local Tx1 = texture { pigment { PgNext translate <-1,-1, 0>*Delta } 
finish { ambient NumLayers * NeighborFactor } }
#local Tx2 = texture { pigment { PgNext translate <-1, 0, 0>*Delta } 
finish { ambient NumLayers * NeighborFactor } }
#local Tx3 = texture { pigment { PgNext translate <-1, 1, 0>*Delta } 
finish { ambient NumLayers * NeighborFactor } }
#local Tx4 = texture { pigment { PgNext translate < 0,-1, 0>*Delta } 
finish { ambient NumLayers * NeighborFactor } }
#local Tx5 = texture { pigment { PgNext translate < 0, 0, 0>*Delta } 
finish { ambient NumLayers * CellFactor } }
#local Tx6 = texture { pigment { PgNext translate < 0, 1, 0>*Delta } 
finish { ambient NumLayers * NeighborFactor } }
#local Tx7 = texture { pigment { PgNext translate < 1,-1, 0>*Delta } 
finish { ambient NumLayers * NeighborFactor } }
#local Tx8 = texture { pigment { PgNext translate < 1, 0, 0>*Delta } 
finish { ambient NumLayers * NeighborFactor } }
#local Tx9 = texture { pigment { PgNext translate < 1, 1, 0>*Delta } 
finish { ambient NumLayers * NeighborFactor } }

#local TxOutput = texture {
   average
   texture_map {
     [1 Tx1 ]
     [1 Tx2 ]
     [1 Tx3 ]
     [1 Tx4 ]
     [1 Tx5 ]
     [1 Tx6 ]
     [1 Tx7 ]
     [1 Tx8 ]
     [1 Tx9 ]
   }
}

box { <-1.5, -0.5, 0.0>, <1.5, 0.5, 0.0> texture { TxOutput } }

--------------------------------------


Post a reply to this message

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