diff --git a/contrib/automata.factor b/contrib/automata.factor index 60d0754a45..1f2c8553aa 100644 --- a/contrib/automata.factor +++ b/contrib/automata.factor @@ -8,7 +8,7 @@ REQUIRES: math slate vars ; USING: parser kernel hashtables namespaces sequences math io math-contrib threads strings arrays prettyprint -gadgets gadgets-editors gadgets-frames gadgets-buttons gadgets-grids +gadgets gadgets-text gadgets-frames gadgets-buttons gadgets-grids vars slate ; IN: automata @@ -151,27 +151,28 @@ white set-clear-color black set-color clear-window ; ! automata-window ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +: [bind] ( ns quot -- quot ) \ bind 3array >quotation ; + : bind-button ( ns button -- ) tuck button-quot \ bind 3array >quotation swap set-button-quot ; -VARS: ns editor frame ; +VARS: ns field frame ; : init-slate ( -- ) t over set-gadget-clipped? self set ; -: init-editor ( -- ) "" >editor ; +: init-field ( -- ) +f ns> [ editor-text string>number set-rule start-center ] [bind] +>field ; -: set-editor-rule ( n -- ) number>string editor> set-editor-text ; - -: open-rule ( -- ) editor> editor-text string>number set-rule start-center ; +: set-field-rule ( n -- ) number>string field> set-editor-text ; : automata-window ( -- ) >frame [ ] make-hash >ns -ns> [ init-rule init-slate init-editor ] bind -ns> [ editor> ] bind 1array +ns> [ init-rule init-slate init-field ] bind +ns> [ field> ] bind 1array ns> -{ { "Open" [ open-rule ] } - { "Center" [ start-center ] } +{ { "Center" [ start-center ] } { "Random" [ start-random ] } { "Continue" [ run-rule ] } } [ first2 tuck bind-button ] @@ -181,7 +182,7 @@ ns> [ self get ] bind frame> @center grid-add frame> "Cellular Automata" open-titled-window 1000 sleep -ns> [ interesting random-item set-editor-rule open-rule ] bind ; +ns> [ interesting random-item dup set-field-rule set-rule start-center ] bind ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!