Script to display evolution of 2D patterns in 3 dimensions

For scripts to aid with computation or simulation in cellular automata.
Post Reply
User avatar
SuperSupermario24
Posts: 121
Joined: July 22nd, 2014, 12:59 pm
Location: Within the infinite expanses of the Life universe

Script to display evolution of 2D patterns in 3 dimensions

Post by 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:

Code: Select all

-- 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:
A glider moving across a torus
A glider moving across a torus
3D_1.png (93.93 KiB) Viewed 6542 times
A spacefiller running for 72 generations
A spacefiller running for 72 generations
3D_2.png (152.24 KiB) Viewed 6542 times
Photons colliding in Seeds
Photons colliding in Seeds
3D_3.png (238.68 KiB) Viewed 6542 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.

Code: Select all

bobo2b3o2b2o2bo3bobo$obobobo3bo2bobo3bobo$obobob2o2bo2bobo3bobo$o3bobo3bo2bobobobo$o3bob3o2b2o3bobo2bo!

User avatar
Saka
Posts: 3627
Joined: June 19th, 2015, 8:50 pm
Location: Indonesia
Contact:

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

Post by 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?

User avatar
SuperSupermario24
Posts: 121
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

Post by 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:
Glider going across a torus with step size 16
Glider going across a torus with step size 16
3D_4.png (72.43 KiB) Viewed 6498 times
Thanks for the idea :D

Code: Select all

bobo2b3o2b2o2bo3bobo$obobobo3bo2bobo3bobo$obobob2o2bo2bobo3bobo$o3bobo3bo2bobobobo$o3bob3o2b2o3bobo2bo!

Gamedziner
Posts: 795
Joined: May 30th, 2016, 8:47 pm
Location: Milky Way Galaxy: Planet Earth

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

Post by Gamedziner » August 19th, 2018, 2:05 pm

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

Code: Select all

x = 81, y = 96, rule = LifeHistory
58.2A$58.2A3$59.2A17.2A$59.2A17.2A3$79.2A$79.2A2$57.A$56.A$56.3A4$27.
A$27.A.A$27.2A21$3.2A$3.2A2.2A$7.2A18$7.2A$7.2A2.2A$11.2A11$2A$2A2.2A
$4.2A18$4.2A$4.2A2.2A$8.2A!

User avatar
Saka
Posts: 3627
Joined: June 19th, 2015, 8:50 pm
Location: Indonesia
Contact:

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

Post by 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

User avatar
gameoflifemaniac
Posts: 1242
Joined: January 22nd, 2017, 11:17 am
Location: There too

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

Post by 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!
I was so socially awkward in the past and it will haunt me for the rest of my life.

Code: Select all

b4o25bo$o29bo$b3o3b3o2bob2o2bob2o2bo3bobo$4bobo3bob2o2bob2o2bobo3bobo$
4bobo3bobo5bo5bo3bobo$o3bobo3bobo5bo6b4o$b3o3b3o2bo5bo9bobo$24b4o!

User avatar
calcyman
Moderator
Posts: 2932
Joined: June 1st, 2009, 4:32 pm

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

Post by 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
Saka
Posts: 3627
Joined: June 19th, 2015, 8:50 pm
Location: Indonesia
Contact:

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

Post by 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.

User avatar
gameoflifemaniac
Posts: 1242
Joined: January 22nd, 2017, 11:17 am
Location: There too

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

Post by 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
I was so socially awkward in the past and it will haunt me for the rest of my life.

Code: Select all

b4o25bo$o29bo$b3o3b3o2bob2o2bob2o2bo3bobo$4bobo3bob2o2bob2o2bobo3bobo$
4bobo3bobo5bo5bo3bobo$o3bobo3bobo5bo6b4o$b3o3b3o2bo5bo9bobo$24b4o!

Post Reply