2 USING: kernel accessors locals namespaces sequences threads
3 math math.order math.vectors
5 colors opengl ui ui.gadgets ui.gestures ui.render
11 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
13 ! Example 33-15 from the Processing book
15 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
17 ! Return the mouse location relative to the current gadget
19 : mouse ( -- point ) hand-loc get hand-gadget get screen-loc v- ;
21 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
23 : point-list ( n -- seq ) [ drop { 0 0 } ] map <circular> ;
25 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
27 : percent->radius ( percent -- radius ) neg 1 + 25 * 5 max ;
29 : dot ( pos percent -- ) percent->radius circle ;
31 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
33 TUPLE: <trails-gadget> < gadget paused points ;
35 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
37 :: iterate-system ( GADGET -- )
39 ! Add a valid point if the mouse is in the gadget
40 ! Otherwise, add an "invisible" point
42 hand-gadget get GADGET =
43 [ mouse GADGET points>> push-circular ]
44 [ { -10 -10 } GADGET points>> push-circular ]
47 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
49 :: start-trails-thread ( GADGET -- )
50 GADGET f >>paused drop
55 [ GADGET iterate-system GADGET relayout-1 1 milliseconds sleep t ]
62 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
64 M: <trails-gadget> pref-dim* ( <trails-gadget> -- dim ) drop { 500 500 } ;
66 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
68 : each-percent ( seq quot -- )
76 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
78 M:: <trails-gadget> draw-gadget* ( GADGET -- )
81 T{ rgba f 1 1 1 0.4 } \ fill-color set ! White, with some transparency
82 T{ rgba f 0 0 0 0 } \ stroke-color set ! no stroke
86 GADGET points>> [ dot ] each-percent
90 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
92 : trails-gadget ( -- <trails-gadget> )
94 <trails-gadget> new-gadget
96 300 point-list >>points
100 dup start-trails-thread ;
102 : trails-window ( -- ) [ trails-gadget "Trails" open-window ] with-ui ;
104 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!