2 USING: kernel namespaces threads sequences math math.vectors
3 opengl.gl opengl colors ui ui.gadgets ui.gadgets.slate
4 fry rewrite-closures vars springies accessors math.geometry.rect ;
8 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10 : draw-node ( node -- ) pos>> { -5 -5 } v+ [ { 10 10 } gl-rect ] with-translation ;
12 : draw-spring ( spring -- )
13 [ node-a>> pos>> ] [ node-b>> pos>> ] bi gl-line ;
15 : draw-nodes ( -- ) nodes> [ draw-node ] each ;
17 : draw-springs ( -- ) springs> [ draw-spring ] each ;
19 : set-projection ( -- )
20 GL_PROJECTION glMatrixMode
22 0 world-width 1- 0 world-height 1- -1 1 glOrtho
23 GL_MODELVIEW glMatrixMode
26 ! : display ( -- ) set-projection black gl-color draw-nodes draw-springs ;
28 : display ( -- ) set-projection black gl-color draw-nodes draw-springs ;
30 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
36 : update-world-size ( -- ) slate> rect-dim >world-size ;
38 : refresh-slate ( -- ) slate> relayout-1 ;
49 : maybe-loop ( -- ) loop> [ run ] when ;
51 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
53 : springies-window* ( -- )
57 C[ { 500 500 } >world-size loop on [ run ] in-thread ] >>graft
58 C[ loop off ] >>ungraft
59 [ >slate ] [ "Springies" open-window ] bi ;
61 : springies-window ( -- ) [ [ springies-window* ] with-scope ] with-ui ;
63 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
65 : go* ( quot -- ) '[ [ springies-window* 1000 sleep @ ] with-scope ] with-ui ;