about summary refs log tree commit diff stats
path: root/life.teliva
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-11-10 08:54:57 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-11-10 09:01:19 -0800
commitd2d388ffdcf91736531c93460a4e4e9e331008fa (patch)
treed83a2fd21fc8dded525ac0517763edd0863f9e70 /life.teliva
parent43724435feb64cb11ab77cc08004b9123206c70d (diff)
downloadteliva-d2d388ffdcf91736531c93460a4e4e9e331008fa.tar.gz
some commandline options for life.teliva
Diffstat (limited to 'life.teliva')
-rw-r--r--life.teliva48
1 files changed, 43 insertions, 5 deletions
diff --git a/life.teliva b/life.teliva
index 5d26b72..4ee9864 100644
--- a/life.teliva
+++ b/life.teliva
@@ -186,11 +186,49 @@ function step()
   grid = new_grid
 end
 
-grid[83][172] = 1
-grid[83][173] = 1
-grid[84][173] = 1
-grid[84][174] = 1
-grid[85][173] = 1
+
+if (#arg == 0) then
+  -- by default, start from a deterministically random state
+  for i=1,lines*4 do
+    for j=1,cols*2 do
+      grid[i][j] = math.random(0, 1)
+    end
+  end
+elseif arg[1] == "random" then
+  -- start from a non-deterministically random start state
+  math.randomseed(os.time())
+  for i=1,lines*4 do
+    for j=1,cols*2 do
+      grid[i][j] = math.random(0, 1)
+    end
+  end
+-- Shortcuts for some common patterns
+elseif arg[1] == "pentomino" then
+  -- https://www.conwaylife.com/wiki/Pentomino
+  grid[83][172] = 1
+  grid[83][173] = 1
+  grid[84][173] = 1
+  grid[84][174] = 1
+  grid[85][173] = 1
+elseif arg[1] == "glider" then
+  -- https://www.conwaylife.com/wiki/Glider
+  grid[5][4] = 1
+  grid[6][5] = 1
+  grid[7][3] = 1
+  grid[7][4] = 1
+  grid[7][5] = 1
+elseif arg[1] == "blinker" then
+  -- https://www.conwaylife.com/wiki/Blinker
+  grid[7][3] = 1
+  grid[7][4] = 1
+  grid[7][5] = 1
+elseif arg[1] == "block" then
+  -- https://www.conwaylife.com/wiki/Block
+  grid[5][4] = 1
+  grid[5][5] = 1
+  grid[6][4] = 1
+  grid[6][5] = 1
+end
 
 while true do
   render(window)