diff options
-rw-r--r-- | README | 52 | ||||
-rw-r--r-- | examples/automatarc-eca.lua | 5 | ||||
-rw-r--r-- | misc/run.lua | 37 | ||||
-rw-r--r-- | module/tex/context/third/simpleslides/automata/automata-eca.lua | 10 |
4 files changed, 87 insertions, 17 deletions
@@ -0,0 +1,52 @@ +················································································ +· Automata for ConTeXt · +················································································ + +····· What? ···································································· + +This module provides a means of drawing cellular automata in your context +documents, preferably as backgrounds for presentations. Currently, two kinds of +automata are supported: Conway's Game of Life and Elementary Cellular Automata. +In both cases custom initial states can be loaded as well as the rules +governing the automaton's progress. + +····· How? ····································································· + +Install the Automata package by copying the content of the “module/” directory +into the “texmf-local” of your context distribution; e.g. + +$ cp -r modules/tex/ ~/context/tex/texmf-local/ + +if you happen to have the context minimals installed in you $HOME dir. + +Have a look at the usage examples to get an overview. The usage does not +significantly differ from the other styles the Simple Slides package provides. +You might want to tweak the color definitions in “simpleslides-s-Automaton.tex” +and adapt them for your particular use case. + +Also, try the command line tool “run.lua” from the directory “misc/”. Put it +to some safe directory together with the scripts from +“module/tex/context/third/simpleslides/automata/automata-eca.lua” and invoke it +on one of the examples: + +$ texlua run.lua --file=sships.gol --n=90 +$ texlua run.lua --file=w50m.eca --n=20 --rule=182 + +····· May I … ? ································································ + +This code is licensed under the GNU GPL v.2 (no later versions) as is the Simple +Slides module. Have a look at the file “COPYING” to find out more. + +····· Who? ····································································· + +Written by Philipp Gesang, blame all bugs on him. (Actually, I'd appreciate your +reporting a bug to me.) + +http://bitbucket.org/phg/ +string.format("%s@%s", "megas.kapaneus", "googlemail.com") + +····· Why? ····································································· + +Why not? + +················································································ diff --git a/examples/automatarc-eca.lua b/examples/automatarc-eca.lua index a56833e..ea1e27b 100644 --- a/examples/automatarc-eca.lua +++ b/examples/automatarc-eca.lua @@ -5,9 +5,10 @@ mplife.setup.rc = {} do local c = {} - c.file = "initial-eca/w40r.eca" - c.init = eca.parse_file(c.file) c.rule = eca.gen_rule(110) + c.n = 40 + + c.from = "" c.clip = "left" diff --git a/misc/run.lua b/misc/run.lua index 0fcc030..b90f90d 100644 --- a/misc/run.lua +++ b/misc/run.lua @@ -25,7 +25,11 @@ GOTO http://www.luatex.org/ return 1 end -require "life" +mplife = {} +mplife.setup = {} + +require "automata-life" +require "automata-eca" local C, Cs, Ct, P, R, S, match = lpeg.C, lpeg.Cs, lpeg.Ct, lpeg.P, lpeg.R, lpeg.S, lpeg.match @@ -102,15 +106,8 @@ function life (current) return 0 end -function eca(current) - local eca = require "eca" - -- how many lines to draw - current.n = tonumber(current.kv_args.n) or 30 - current.aspect = tonumber(current.kv_args.aspect) or 3/4 - current.rule = eca.gen_rule(tonumber(current.kv_args.rule) or 110) - current.from = eca.parse_file(current.kv_args.file) - current.framesize = math.floor(current.aspect * current.from:len()) - +function elem(current) + print (current.n, type(current.n)) for n=1,current.n,1 do gol.pre_section(current.from:len(), n) eca.successive(current) @@ -121,14 +118,30 @@ end function main () local current = {} current.kv_args = get_args() - current.file = current.kv_args.file or "10x10_glider.gol" + current.file = current.kv_args.file local p_suf = P"." * (1-P".")^3 * -P(1) local p_fn = (1-p_suf)^1 * C(p_suf) local suffix = p_fn:match(current.file) or ".gol" -- assume .gol format as default if suffix == ".eca" then - return eca(current) + require "automatarc-eca" + for i,j in pairs(mplife.setup.rc) do + current[i] = mplife.setup.rc[i] + end + current.aspect = tonumber(current.kv_args.aspect) or 3/4 + current.rule = eca.gen_rule(tonumber(current.kv_args.rule) or 110) + current.from = eca.parse_file(current.kv_args.file) + current.framesize = math.floor(current.aspect * current.from:len()) + + current.n = tonumber(current.kv_args.n) + end + + current.n = tonumber(current.kv_args.n) + + if suffix == ".eca" then + mplife.setup.current = current + return elem(current) else return life(current) end diff --git a/module/tex/context/third/simpleslides/automata/automata-eca.lua b/module/tex/context/third/simpleslides/automata/automata-eca.lua index 95d1f71..27450ba 100644 --- a/module/tex/context/third/simpleslides/automata/automata-eca.lua +++ b/module/tex/context/third/simpleslides/automata/automata-eca.lua @@ -10,7 +10,11 @@ -------------------------------------------------------------------------------- -- -environment.loadluafile( "automata-life" ) +if context then + environment.loadluafile( "automata-life" ) +else + require "automata-life" +end local help = gol.helpers @@ -82,11 +86,11 @@ function eca.gen_frame(from, lines, rule) local cnt = 1 local c = mplife.setup.current - local new = { [1] = eca.stripcells(from, c.clip, c.diff ) } + local new = { [1] = eca.stripcells(from, c.clip, c.diff or 0 ) } repeat from = eca.next_line(from, rule) - table.insert( new, eca.stripcells(from, c.clip, c.diff) ) + table.insert( new, eca.stripcells(from, c.clip, c.diff or 0) ) cnt = cnt + 1 until cnt == lines return eca.next_line(from, rule), new |