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 ungraft* ( trails-gadget -- ) t >>paused drop ;
63 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
65 M: trails-gadget pref-dim* ( trails-gadget -- dim ) drop { 500 500 } ;
67 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
69 : each-percent ( seq quot -- )
72 [ iota ] [ [ / ] curry ] bi
77 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
79 M:: trails-gadget draw-gadget* ( GADGET -- )
80 T{ rgba f 1 1 1 0.4 } \ fill-color set ! White, with some transparency
81 T{ rgba f 0 0 0 0 } \ stroke-color set ! no stroke
85 GADGET points>> [ dot ] each-percent ;
87 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
89 : <trails-gadget> ( -- trails-gadget )
93 300 point-list >>points
97 dup start-trails-thread ;
99 MAIN-WINDOW: trails-window
100 { { title "Trails" } }
101 <trails-gadget> >>gadgets ;