summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--life.lua25
-rw-r--r--mplife.lua53
-rw-r--r--mpliferc-global.lua56
-rw-r--r--mpliferc.lua48
-rw-r--r--simpleslides-s-Automaton.tex2
5 files changed, 136 insertions, 48 deletions
diff --git a/life.lua b/life.lua
index 42a17bd..127974b 100644
--- a/life.lua
+++ b/life.lua
@@ -71,7 +71,6 @@ end
-- => “birth” of a new cell if exactly 3 adjacent cells are “alive”
-- => “staying alive” of cells with two or three adjacent “live” cells
function gol.parse_rule (raw_rule)
- print("HERE!!>>>>>>>>>>> "..raw_rule)
local help = gol.helpers
local b_s = help.split_once (raw_rule, "/.-")
local tmp_b = help.strip(b_s[1], "B")
@@ -151,19 +150,31 @@ function gol.parse_file (fname)
end
local file = assert(io.open(fname, "r"), "Not a file: " .. fname)
- for line in file:lines() do
- if not len then len = string.len(line) end
+ local data = file:read("*all")
+ file:close()
- if len ~= string.len(line) then
+ local cell = R"09" + P"D"
+ local nl = Cs(P"\n") / ""
+ local line = Cs(cell^1) / function (l)
+ if not len then len = string.len(l) end
+ if len ~= string.len(l) then
-- inconsistent horizontal sizes; kill off program
return nil
else
- table.insert(tmp, line)
+ table.insert(tmp,l)
end
end
- file:close()
- return tmp
+ local gol_parser = Cs(line * (nl + line)^0)
+
+ if gol_parser:match(data) then
+ if context then
+ context.writestatus("simpleslides", "Sucessfully loaded frame from "..fname..".")
+ end
+ return tmp
+ else
+ return false
+ end
end
--- Computing single lines and whole frames and intervals thereof
diff --git a/mplife.lua b/mplife.lua
index c3067ab..7133a59 100644
--- a/mplife.lua
+++ b/mplife.lua
@@ -22,48 +22,23 @@ local C, Cs, Ct, P, R, S, match = lpeg.C, lpeg.Cs, lpeg.Ct, lpeg.P, lpeg.R, lpeg
mplife = {}
mplife.setup = mplife.setup or {}
-mplife.setup.current = mplife.setup.current or {}
-do
- local c = mplife.setup.current
+if context then
+ environment.loadluafile "mpliferc-global"
+ environment.loadluafile "mpliferc"
+else -- assuming we're staying in pwd
+ require "mpliferc"
+end
- --c.file = c.file or "examples/10x10_glider.gol"
- --c.file = c.file or "examples/gliders.gol"
- --c.file = c.file or "examples/ggun.gol"
- c.file = c.file or "examples/sships.gol"
- c.rule = c.rule or gol.parse_rule("B3/S23") -- default Conway
- c.init = c.init or gol.parse_file(c.file)
- c.last = c.init -- for successive mode
-
- c.pensize = .1
- c.color = { r = .6, g = .6, b = .8 }
- c.opacity = 1/3
- c.fade = true
- c.gestalt = "unitsquare" -- try "unitcircle"
-
- c.firstframe = 1
- c.frames = 5
-
- c.preamble = [[
-\setupcolors[state=start]
-\setupbackgrounds[state=start]
-\setuppapersize[S6][S6]
-
-\setuppagenumbering[state=stop,location=]
-
-\defineoverlay[back][\ctxlua{mplife.successive()}]
-
-\setupbackgrounds [page] [background=back]
-]]
- c.before_frame = [[
-\startMPcode
-pickup pencircle xyscaled (.25*]] .. c.pensize .. [[pt, ]] .. c.pensize .. [[pt) rotated 45;
-]]
- c.after_frame = [[
-currentpicture := currentpicture xysized (\the\paperwidth, \the\paperheight);
-\stopMPcode
-]]
+mplife.setup.current = {}
+
+do
+ local g, r, c = mplife.setup.global, mplife.setup.rc, mplife.setup.current
+ for key,_ in pairs(g) do
+ print(key, ">>>", tostring(r[key]) .. " or " .. tostring(g[key]))
+ c[key] = r[key] or g[key] -- prefer local settings
+ end
mplife.setup.current = c
end
diff --git a/mpliferc-global.lua b/mpliferc-global.lua
new file mode 100644
index 0000000..83ab6eb
--- /dev/null
+++ b/mpliferc-global.lua
@@ -0,0 +1,56 @@
+--
+--------------------------------------------------------------------------------
+-- FILE: mpliferc-global.lua
+-- USAGE: with ConTeXt
+-- DESCRIPTION: default settings for the automaton module
+-- AUTHOR: Philipp Gesang (Phg), <megas.kapaneus@gmail.com>
+-- VERSION: 1.0
+-- CREATED: 13/08/10 10:35:46 CEST
+--------------------------------------------------------------------------------
+--
+
+if not mplife then return 1 end
+
+mplife.setup.global = {}
+
+do
+ local c = {}
+
+ c.file = "examples/sships.gol"
+ c.rule = gol.parse_rule("B3/S23") -- default Conway
+ c.init = gol.parse_file(c.file)
+ c.last = c.init -- for successive mode
+
+ c.pensize = .1
+ c.color = { r = .6, g = .6, b = .8 }
+ c.opacity = 1/3
+ c.fade = true
+ c.gestalt = "unitsquare" -- try "unitcircle"
+
+ c.firstframe = 1
+ c.frames = 5
+
+ c.preamble = [[
+\setupcolors[state=start]
+\setupbackgrounds[state=start]
+\setuppapersize[S6][S6]
+
+\setuppagenumbering[state=stop,location=]
+
+\defineoverlay[back][\ctxlua{mplife.successive()}]
+
+\setupbackgrounds [page] [background=back]
+]]
+ c.before_frame = [[
+\startMPcode
+pickup pencircle xyscaled (.25*]] .. c.pensize .. [[pt, ]] .. c.pensize .. [[pt) rotated 45;
+]]
+ c.after_frame = [[
+currentpicture := currentpicture xysized (\the\paperwidth, \the\paperheight);
+\stopMPcode
+]]
+
+ mplife.setup.global = c
+end
+
+return mplife.setup.global
diff --git a/mpliferc.lua b/mpliferc.lua
new file mode 100644
index 0000000..00bd880
--- /dev/null
+++ b/mpliferc.lua
@@ -0,0 +1,48 @@
+if not mplife then return 1 end
+
+mplife.setup.rc = {}
+
+do
+ local c = {}
+
+ --c.file = "examples/10x10_glider.gol"
+ --c.file = "examples/gliders.gol"
+ c.file = "examples/ggun.gol"
+ --c.file = "examples/sships.gol"
+ c.rule = gol.parse_rule("B3/S23") -- default Conway
+ c.init = gol.parse_file(c.file)
+ c.last = c.init -- for successive mode
+
+ c.pensize = .1
+ c.color = { r = .6, g = .6, b = .8 }
+ c.opacity = 1/3
+ c.fade = true
+ c.gestalt = "unitsquare" -- try "unitcircle"
+
+ c.firstframe = 1
+ c.frames = 5
+
+ c.preamble = [[
+\setupcolors[state=start]
+\setupbackgrounds[state=start]
+\setuppapersize[S6][S6]
+
+\setuppagenumbering[state=stop,location=]
+
+\defineoverlay[back][\ctxlua{mplife.successive()}]
+
+\setupbackgrounds [page] [background=back]
+]]
+ c.before_frame = [[
+\startMPcode
+pickup pencircle xyscaled (.25*]] .. c.pensize .. [[pt, ]] .. c.pensize .. [[pt) rotated 45;
+]]
+ c.after_frame = [[
+currentpicture := currentpicture xysized (\the\paperwidth, \the\paperheight);
+\stopMPcode
+]]
+
+ mplife.setup.rc = c
+end
+
+return mplife.setup.rc
diff --git a/simpleslides-s-Automaton.tex b/simpleslides-s-Automaton.tex
index 1b4b277..3300844 100644
--- a/simpleslides-s-Automaton.tex
+++ b/simpleslides-s-Automaton.tex
@@ -96,8 +96,6 @@
%D Set the initial Game of Life snapshot (from file) and the rule, if given.
-%\doifsomething{\currentmoduleparameter{key}}{\setupsomething[key=\currentmoduleparameter{key}]}
-
\doifsomething{\moduleparameter{simpleslides}{file}}{\ctxlua
{mplife.setup.current.file = "\luaescapestring{\moduleparameter{simpleslides}{file}}"
mplife.setup.current.init = gol.parse_file(mplife.setup.current.file)