Maya

3D Game of life simulator

3D game of life

This short workflow helps you easily create game of life simulations (the cellular automaton by John Conway) :

  • Create a 2d fluid container (without emitter)
    Rotate it by 90° on X
  • In the fluid properties, check auto resize, set max resolution to 1000, auto resize margin to 2, and buoyancy to 0 (in Contents details > Density)
  • Create a nParticle emitter and delete the emitter
  • In the expression editor, paste this expression (gently made by Duncan Brinsmead) and click “create” :
if( frame > 1 ){
 float $res[] = `getAttr "fluidShape1.resolution"`;
 vector $off = `getAttr "fluidShape1.dynamicOffset"`;
 int $rx = $res[0];
 int $ry = $res[1];float $dens[] = `getFluidAttr -at "density" fluidShape1`;float $dx = 0.1;
 float $dz = 0.04;
 float $hx = $rx * $dx * 0.5 - $off.x;
 float $hy = $ry * $dx * 0.5 - $off.y;
 string $cmd = "emit -o nParticleShape1";
 int $xi, $yi;
 for( $yi = 1; $yi < $ry-1; $yi++ ){
 for( $xi = 1; $xi < $rx-1; $xi++ ){
 int $i = $xi + $yi * $rx;
 int $val = $dens[$i] > 0.1;
 int $neighbors = ($dens[($i+1)] > 0.1) + ($dens[($i-1)] > 0.1) + ($dens[($i+$rx)] >0.1) + ($dens[($i-$rx)] >0.1)
 + ($dens[($i+1+$rx)] > 0.1) + ($dens[($i-1+$rx)] > 0.1) + ($dens[($i+1-$rx)] >0.1) + ($dens[($i-1-$rx)] >0.1);
 if( $val ){
 $cmd += (" -pos "+($dx * ((float)$xi+0.5) - $hx)+" 0 "+($dx * (float)($yi+0.5)-$hy));
 if( $neighbors < 2 || $neighbors > 3 ){
 setFluidAttr -at "density" -fv 0 -xi $xi -yi $yi fluidShape1;
 }
 } else if( $neighbors == 3 ) {
 setFluidAttr -at "density" -fv 0.3 -xi $xi -yi $yi fluidShape1;
 }
 }
 }
 eval $cmd;
 }

► If you want each new step to appear on top :
In nParticleShape1 > Per Particle (array) attributes > Position, right click and select “create an expression” :

pos = pos + <<0, frame/10, 0>>

(frame/10 is the Y translation for perfect cubes but you can type any value.)

► If you want each new step to appear at the bottom :
In nParticle1 > Translate Y, create this expression :

nParticle1.translateY = frame/10

► If you want a 2D game of life, just set the particle lifespan to 0.001

To use an image file for the start :

  • Check your image’s dimensions
  • In fluidShape1, Set the fluid’s base resolution to the same as the image’s width or height (the biggest one), and set the x and y Size to the same as the image’s dimensions divided by 10.
  • Select fluid1 and the paint fluids tool
  • Go to start on your timeline
  • in Tool Settings panel > Attribute maps > Import, select your image.
  • Go to start on your timeline once again.

To use cubes :

  • create a 0.1 sized cube
  • Select it, then nParticle1
  • Click on nParticles > instancer

And Voilà !

Here’s an example of what you can do with it :