2007-10-08 16:00:01 -04:00
|
|
|
|
2008-03-29 00:00:20 -04:00
|
|
|
USING: kernel namespaces threads sequences math math.vectors
|
2007-10-08 16:00:01 -04:00
|
|
|
opengl.gl opengl colors ui ui.gadgets ui.gadgets.slate
|
2008-07-11 20:28:48 -04:00
|
|
|
fry rewrite-closures vars springies accessors math.geometry.rect ;
|
2007-10-08 16:00:01 -04:00
|
|
|
|
|
|
|
IN: springies.ui
|
|
|
|
|
|
|
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
2008-11-16 14:07:03 -05:00
|
|
|
: draw-node ( node -- ) pos>> { -5 -5 } v+ [ { 10 10 } gl-rect ] with-translation ;
|
2007-10-08 16:00:01 -04:00
|
|
|
|
|
|
|
: draw-spring ( spring -- )
|
2008-09-01 19:44:27 -04:00
|
|
|
[ node-a>> pos>> ] [ node-b>> pos>> ] bi gl-line ;
|
2007-10-08 16:00:01 -04:00
|
|
|
|
|
|
|
: draw-nodes ( -- ) nodes> [ draw-node ] each ;
|
|
|
|
|
|
|
|
: draw-springs ( -- ) springs> [ draw-spring ] each ;
|
|
|
|
|
|
|
|
: set-projection ( -- )
|
|
|
|
GL_PROJECTION glMatrixMode
|
|
|
|
glLoadIdentity
|
|
|
|
0 world-width 1- 0 world-height 1- -1 1 glOrtho
|
|
|
|
GL_MODELVIEW glMatrixMode
|
|
|
|
glLoadIdentity ;
|
|
|
|
|
2008-07-31 17:11:03 -04:00
|
|
|
! : display ( -- ) set-projection black gl-color draw-nodes draw-springs ;
|
|
|
|
|
2008-11-11 04:10:41 -05:00
|
|
|
: display ( -- ) set-projection black gl-color draw-nodes draw-springs ;
|
2007-10-08 16:00:01 -04:00
|
|
|
|
|
|
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
|
|
|
VAR: slate
|
|
|
|
|
|
|
|
VAR: loop
|
|
|
|
|
|
|
|
: update-world-size ( -- ) slate> rect-dim >world-size ;
|
|
|
|
|
|
|
|
: refresh-slate ( -- ) slate> relayout-1 ;
|
|
|
|
|
|
|
|
DEFER: maybe-loop
|
|
|
|
|
|
|
|
: run ( -- )
|
|
|
|
update-world-size
|
|
|
|
iterate-system
|
|
|
|
refresh-slate
|
|
|
|
yield
|
|
|
|
maybe-loop ;
|
|
|
|
|
|
|
|
: maybe-loop ( -- ) loop> [ run ] when ;
|
|
|
|
|
|
|
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
|
|
|
: springies-window* ( -- )
|
|
|
|
|
2008-09-02 17:13:43 -04:00
|
|
|
C[ display ] <slate>
|
|
|
|
{ 800 600 } >>pdim
|
|
|
|
C[ { 500 500 } >world-size loop on [ run ] in-thread ] >>graft
|
|
|
|
C[ loop off ] >>ungraft
|
|
|
|
[ >slate ] [ "Springies" open-window ] bi ;
|
2007-10-08 16:00:01 -04:00
|
|
|
|
2007-10-10 01:09:58 -04:00
|
|
|
: springies-window ( -- ) [ [ springies-window* ] with-scope ] with-ui ;
|
|
|
|
|
|
|
|
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
2008-09-02 17:13:43 -04:00
|
|
|
: go* ( quot -- ) '[ [ springies-window* 1000 sleep @ ] with-scope ] with-ui ;
|