1 USING: accessors calendar circular colors colors.constants
2 kernel locals math math.order math.vectors namespaces opengl
3 processing.shapes sequences threads ui ui.gadgets ui.gestures
8 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10 ! Example 33-15 from the Processing book
12 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14 ! Return the mouse location relative to the current gadget
16 : mouse ( -- point ) hand-loc get hand-gadget get screen-loc v- ;
18 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
20 : point-list ( n -- seq ) [ { 0 0 } ] replicate <circular> ;
22 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
24 : percent->radius ( percent -- radius ) neg 1 + 25 * 5 max ;
26 : dot ( pos percent -- ) percent->radius circle ;
28 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
30 TUPLE: trails-gadget < gadget paused points ;
32 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
34 :: iterate-system ( GADGET -- )
36 ! Add a valid point if the mouse is in the gadget
37 ! Otherwise, add an "invisible" point
39 hand-gadget get GADGET =
40 [ mouse GADGET points>> circular-push ]
41 [ { -10 -10 } GADGET points>> circular-push ]
44 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
46 :: start-trails-thread ( GADGET -- )
47 GADGET f >>paused drop
52 [ GADGET iterate-system GADGET relayout-1 1 milliseconds sleep t ]
59 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
61 M: trails-gadget pref-dim* ( trails-gadget -- dim ) drop { 500 500 } ;
63 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
65 : each-percent ( seq quot -- )
68 [ iota ] [ [ / ] curry ] bi
73 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
75 M:: trails-gadget draw-gadget* ( GADGET -- )
76 T{ rgba f 1 1 1 0.4 } \ fill-color set ! White, with some transparency
77 T{ rgba f 0 0 0 0 } \ stroke-color set ! no stroke
81 GADGET points>> [ dot ] each-percent ;
83 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
85 : <trails-gadget> ( -- trails-gadget )
89 300 point-list >>points
93 dup start-trails-thread ;
95 : trails-window ( -- ) [ <trails-gadget> "Trails" open-window ] with-ui ;
97 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!