ConwayLife.com - A community for Conway's Game of Life and related cellular automata
Home  •  LifeWiki  •  Forums  •  Download Golly

Script to display evolution of 2D patterns in 3 dimensions

For scripts to aid with computation or simulation in cellular automata.

Script to display evolution of 2D patterns in 3 dimensions

Postby SuperSupermario24 » August 18th, 2018, 2:26 am

As the title suggests, I have created a script that uses 3D.lua to display the entire evolution of a two-dimensional pattern, using the Y dimension as the time dimension.

Here is the script:
-- For 3D.lua (make sure to copy this line)

-- This script will use 3D.lua to display the evolution of a
-- two-dimensional rule in a bounded grid, using Y as the time
-- dimension.

-- It will generate up to 99 steps of any size in any two-state rule,
-- and any kind of bounded grid with dimensions <= 100. (The size
-- limitations are due to the maximum grid size of 3D.lua.)

-- How to use:
-- 1. In Golly's normal interface, create a pattern using a 2-state
--  rule, in a bounded grid with any dimensions <= 100.
-- 2. Start 3D.lua, and run this script through it.
-- 3. Enter the number of steps to run.

-- By SuperSupermario24, 2018-08-18

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

local g = golly()
local gp = require "gplus"

-- function that displays an error message and aborts
-- (can't use g.exit() with a string argument because that bugs 3D.lua)
local function raiseError(message)
    g.warn(message)
    g.exit()
end

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

-- preliminary error-checking
if g.numstates() > 2 then
    raiseError("2D rule simulated cannot have more than 2 states.")
elseif g.getwidth() == 0 or g.getheight() == 0 then
    raiseError("2D universe must be bounded.")
elseif g.getwidth() > 100 or g.getheight() > 100 then
    raiseError("2D universe cannot have a dimension that is greater than 100.")
end

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

-- clear 3D grid
NewPattern()

-- get number of steps and step size
local genstring = g.getstring("Enter steps and optional step size (separated by a space):", "99 1", "Enter generations:")
local numgens, step = gp.split(genstring, " ")

-- convert to numbers
numgens = tonumber(numgens)

-- set default step size to 1 if not entered
if step == nil then
    step = 1
else
    step = tonumber(step)
end

-- check if valid generation and step count
if numgens < 0 then
    g.warn("Cannot run fewer than 0 generations. Running 0 generations instead...")
    numgens = 0
elseif numgens > 99 then -- 99 is max because gen 0 is included
    g.warn("Cannot run more than 99 steps. Running 99 steps instead...")
    numgens = 99
end

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

-- set grid size to highest out of universe width, height, and number of gens displayed
local gridsize = math.max(g.getwidth(), g.getheight(), numgens + 1)
SetGridSize(gridsize)

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

-- set initial current plane to lowest available y value
local currenty = math.ceil(-gridsize / 2)

for i = 1, numgens + 1 do
    if not g.empty() then
        -- get all the cells in the current universe
        local array2d = g.getcells(g.getrect())
       
        -- create 3D cell array out of 2D cell array, using 0 as Y coordinate of all of them
        local array3d = {}
        for i = 1, #array2d / 2 do
            table.insert(array3d, {array2d[2*i - 1], 0, array2d[2*i]})
        end
       
        -- put the cells in current plane
        PutCells(array3d, 0, currenty, 0)
       
        -- if not finished, update the pattern and move current plane up
        if i ~= numgens + 1 then
            g.run(step)
            currenty = currenty + 1
        end
    end
end

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

-- set current mode to hand cursor (otherwise it will be set to draw)
MoveMode()

The script uses Golly's regular 2D universe in order to generate each step behind the scenes. As such, you don't need to fiddle with the 3D editing interface to enter a pattern to simulate; just enter a pattern using the regular Golly interface, and then open 3D.lua and run this script through it.

It will run any pattern for up to 99 steps (due to the max grid size in 3D.lua being 100, and the fact that it will include generation 0), of any step size. It supports any two-state rule, in any bounded grid where the X and Y dimensions are both 100 or less. The type of bounded grid doesn't matter either; go nuts with your tori and Klein bottles and whatnot if you so desire.

Here are a few example pictures:

3D_1.png
A glider moving across a torus
3D_1.png (93.93 KiB) Viewed 624 times

3D_2.png
A spacefiller running for 72 generations
3D_2.png (152.24 KiB) Viewed 624 times

3D_3.png
Photons colliding in Seeds
3D_3.png (238.68 KiB) Viewed 624 times

Let me know what you guys think, or if there are any problems with the script.

UPDATE 1: I've added the ability to enter a custom step size, so that multiple generations may be run per step. This effectively means that the maximum generation count is now theoretically unbounded, although obviously not all of them will be displayed.
Last edited by SuperSupermario24 on August 18th, 2018, 2:10 pm, edited 2 times in total.
bobo2b3o2b2o2bo3bobo$obobobo3bo2bobo3bobo$obobob2o2bo2bobo3bobo$o3bobo3bo2bobobobo$o3bob3o2b2o3bobo2bo!
User avatar
SuperSupermario24
 
Posts: 119
Joined: July 22nd, 2014, 12:59 pm
Location: Within the infinite expanses of the Life universe

Re: Script to display evolution of 2D patterns in 3 dimensions

Postby Saka » August 18th, 2018, 8:27 am

Neat! This is really cool!
What about a step setting so you can do multiple generations per layer?
Proud owner and founder of Sakagolue
x = 17, y = 10, rule = B3/S23
b2ob2obo5b2o$11b4obo$2bob3o2bo2b3o$bo3b2o4b2o$o2bo2bob2o3b4o$bob2obo5b
o2b2o$2b2o4bobo2b3o$bo3b5ob2obobo$2bo5bob2o$4bob2o2bobobo!

(Check gen 2)
User avatar
Saka
 
Posts: 2536
Joined: June 19th, 2015, 8:50 pm
Location: In the kingdom of Sultan Hamengkubuwono X

Re: Script to display evolution of 2D patterns in 3 dimensions

Postby SuperSupermario24 » August 18th, 2018, 2:06 pm

That's actually a really good idea. I went ahead and updated the script to support that, as well as the first post to reflect it.

Here's an example, using a glider going across a torus with a step size of 16:

3D_4.png
Glider going across a torus with step size 16
3D_4.png (72.43 KiB) Viewed 580 times

Thanks for the idea :D
bobo2b3o2b2o2bo3bobo$obobobo3bo2bobo3bobo$obobob2o2bo2bobo3bobo$o3bobo3bo2bobobobo$o3bob3o2b2o3bobo2bo!
User avatar
SuperSupermario24
 
Posts: 119
Joined: July 22nd, 2014, 12:59 pm
Location: Within the infinite expanses of the Life universe

Re: Script to display evolution of 2D patterns in 3 dimensions

Postby Gamedziner » August 19th, 2018, 2:05 pm

I wonder if you could make art with this? For example, pillars could be made with blinkers.
Gamedziner
 
Posts: 507
Joined: May 30th, 2016, 8:47 pm
Location: Milky Way Galaxy: Planet Earth

Re: Script to display evolution of 2D patterns in 3 dimensions

Postby Saka » August 20th, 2018, 5:20 am

Gamedziner wrote:I wonder if you could make art with this? For example, pillars could be made with blinkers.

You definitely can. This is my best "piece" so far in my opinion. It's an LTL spaceship (Though I forgot what ship it is) at step 1 for 99 generations
Image
Proud owner and founder of Sakagolue
x = 17, y = 10, rule = B3/S23
b2ob2obo5b2o$11b4obo$2bob3o2bo2b3o$bo3b2o4b2o$o2bo2bob2o3b4o$bob2obo5b
o2b2o$2b2o4bobo2b3o$bo3b5ob2obobo$2bo5bob2o$4bob2o2bobobo!

(Check gen 2)
User avatar
Saka
 
Posts: 2536
Joined: June 19th, 2015, 8:50 pm
Location: In the kingdom of Sultan Hamengkubuwono X

Re: Script to display evolution of 2D patterns in 3 dimensions

Postby gameoflifemaniac » August 20th, 2018, 10:26 am

When pasting Golly doesn't recognize the clipboard as a script, so Golly tries to paste it as a pattern. Help!
https://www.youtube.com/watch?v=q6EoRBvdVPQ
One big dirty Oro. Yeeeeeeeeee...
User avatar
gameoflifemaniac
 
Posts: 641
Joined: January 22nd, 2017, 11:17 am
Location: There too

Re: Script to display evolution of 2D patterns in 3 dimensions

Postby calcyman » August 20th, 2018, 3:26 pm

gameoflifemaniac wrote:When pasting Golly doesn't recognize the clipboard as a script, so Golly tries to paste it as a pattern. Help!


Run Clipboard rather than Open Clipboard
What do you do with ill crystallographers? Take them to the mono-clinic!
User avatar
calcyman
 
Posts: 1661
Joined: June 1st, 2009, 4:32 pm

Re: Script to display evolution of 2D patterns in 3 dimensions

Postby Saka » August 20th, 2018, 7:18 pm

calcyman wrote:
gameoflifemaniac wrote:When pasting Golly doesn't recognize the clipboard as a script, so Golly tries to paste it as a pattern. Help!


Run Clipboard rather than Open Clipboard

To add to this, make sure you're using the script in 3D.lua.
Proud owner and founder of Sakagolue
x = 17, y = 10, rule = B3/S23
b2ob2obo5b2o$11b4obo$2bob3o2bo2b3o$bo3b2o4b2o$o2bo2bob2o3b4o$bob2obo5b
o2b2o$2b2o4bobo2b3o$bo3b5ob2obobo$2bo5bob2o$4bob2o2bobobo!

(Check gen 2)
User avatar
Saka
 
Posts: 2536
Joined: June 19th, 2015, 8:50 pm
Location: In the kingdom of Sultan Hamengkubuwono X

Re: Script to display evolution of 2D patterns in 3 dimensions

Postby gameoflifemaniac » August 22nd, 2018, 2:27 am

calcyman wrote:
gameoflifemaniac wrote:When pasting Golly doesn't recognize the clipboard as a script, so Golly tries to paste it as a pattern. Help!


Run Clipboard rather than Open Clipboard

I'm dumb
https://www.youtube.com/watch?v=q6EoRBvdVPQ
One big dirty Oro. Yeeeeeeeeee...
User avatar
gameoflifemaniac
 
Posts: 641
Joined: January 22nd, 2017, 11:17 am
Location: There too


Return to Scripts

Who is online

Users browsing this forum: No registered users and 3 guests