2 USING: kernel namespaces math quotations arrays hashtables sequences threads
19 rewrite-closures automata math.geometry.rect newfx ;
23 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
25 : draw-point ( y x value -- ) 1 = [ swap glVertex2i ] [ 2drop ] if ;
27 : draw-line ( y line -- ) 0 swap [ [ 2dup ] dip draw-point 1+ ] each 2drop ;
29 : (draw-bitmap) ( bitmap -- ) 0 swap [ [ dup ] dip draw-line 1+ ] each drop ;
31 : draw-bitmap ( bitmap -- ) GL_POINTS glBegin (draw-bitmap) glEnd ;
33 : display ( -- ) black gl-color bitmap> draw-bitmap ;
35 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
39 ! Call a 'model' quotation with the current 'view'.
41 : with-view ( quot -- )
42 slate> rect-dim first >width
43 slate> rect-dim second >height
47 ! Create a quotation that is appropriate for buttons and gesture handler.
49 : view-action ( quot -- quot ) '[ drop _ with-view ] closed-quot ;
51 : view-button ( label quot -- button ) [ <label> ] dip view-action <bevel-button> ;
53 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
55 ! Helper word to make things less verbose
57 : random-rule ( -- ) set-interesting start-center ;
59 DEFER: automata-window
61 : automata-window* ( -- )
69 "1 - Center" [ start-center ] view-button add-gadget
70 "2 - Random" [ start-random ] view-button add-gadget
71 "3 - Continue" [ run-rule ] view-button add-gadget
72 "5 - Random Rule" [ random-rule ] view-button add-gadget
73 "n - New" [ automata-window ] view-button add-gadget
86 T{ key-down f f "1" } [ start-center ] view-action is
87 T{ key-down f f "2" } [ start-random ] view-action is
88 T{ key-down f f "3" } [ run-rule ] view-action is
89 T{ key-down f f "5" } [ random-rule ] view-action is
90 T{ key-down f f "n" } [ automata-window ] view-action is
94 "Automata" open-window ;
96 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
98 : automata-window ( -- ) [ [ automata-window* ] with-scope ] with-ui ;
100 MAIN: automata-window