Autómato celular 1D em LTK
Depois de escrever esta entrada fiquei com a sensação de que o código precisava de uma representação mais apelativa para o resultado final em vez de uma lista cheia de zeros e uns (ver fim da página do link anterior).
Depois procurar uma maneira eficiente de fazer a coisa e porque as referências que encontrei eram todas em OpenGL, onde os manuais não são fáceis de digerir, resolvi implementar a representação gráfica em tk/tcl, nomeadamente em ltk — LTK - The Lisp Toolkit
![]() |
| Screenshot da janela de LTK da evolução da regra 30. |
Ao contrário dos manuais do OpenGL em que se usa CL, o manual do LTK está muito bem escrito. Com o código e o LTK faz-se
(defun ca-show (all-lst l) (with-ltk () (let* ((c (make-instance 'canvas :background :white)) (lst (car all-lst)) (ny (length (car all-lst))) (nx (length all-lst)) (squares (do ((j 0 (+ j 1))) ((= j nx)) (do ((i 0 (+ i 1))) ((= i ny)) (cond ((= 1 (car (nthcdr i (car (nthcdr j all-lst))))) (create-polygon c (square l (* i l) (* j l)))) (t nil))))) (line-x (do ((i 1 (+ i 1))) ((= i (+ 2 nx))) (create-line c (list l (* i l) (* l (+ 1 ny)) (* i l))))) (line-y (do ((j 1 (+ j 1))) ((= j (+ 2 ny))) (create-line c (list (* j l) l (* j l) (* l (+ 1 nx))))))) (pack c :expand nil :fill :both) ))) (defun square (l x y) (let ((xx (+ x l)) (yy (+ y l))) (list xx yy (+ xx l) yy (+ xx l) (+ yy l) xx (+ yy l))))e com um simples
(ca-show (ca-run xboard xrules 50) 5) obtém-se a figura inicial.
Palavras chave: ltk, lisp, autómato celular 1D
Última actualização/Last updated: 2012-02-26 [15:48]
1999-2011 (c) Tiago Charters de Azevedo
São permitidas cópias textuais parciais/integrais em qualquer meio com/sem alterações desde que se mantenha este aviso.
Verbatim copying and redistribution of this entire page are permitted provided this notice is preserved.

