From: Eduardo Cavazos Date: Tue, 9 Dec 2008 03:30:10 +0000 (-0600) Subject: trails: Un-processify trails X-Git-Tag: 0.94~2285^2~10^2~1^2~3 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=14a54bb97a7a5182073be0d3fbe34e79d8b8fc8e trails: Un-processify trails --- diff --git a/extra/trails/trails.factor b/extra/trails/trails.factor new file mode 100644 index 0000000000..cea5ece9f7 --- /dev/null +++ b/extra/trails/trails.factor @@ -0,0 +1,96 @@ + +USING: kernel accessors locals namespaces sequences sequences.lib threads + math math.order math.vectors + calendar + colors opengl ui ui.gadgets ui.gestures ui.render + circular + processing.shapes ; + +IN: trails + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +! Example 33-15 from the Processing book + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +! Return the mouse location relative to the current gadget + +: mouse ( -- point ) hand-loc get hand-gadget get screen-loc v- ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: point-list ( n -- seq ) [ drop { 0 0 } ] map ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: percent->radius ( percent -- radius ) neg 1 + 25 * 5 max ; + +: dot ( pos percent -- ) percent->radius circle ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +TUPLE: < gadget paused points ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +:: iterate-system ( GADGET -- ) + + ! Add a valid point if the mouse is in the gadget + ! Otherwise, add an "invisible" point + + hand-gadget get GADGET = + [ mouse GADGET points>> push-circular ] + [ { -10 -10 } GADGET points>> push-circular ] + if ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +:: start-trails-thread ( GADGET -- ) + GADGET f >>paused drop + [ + [ + GADGET paused>> + [ f ] + [ GADGET iterate-system GADGET relayout-1 1 milliseconds sleep t ] + if + ] + loop + ] + in-thread ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +M: pref-dim* ( -- dim ) drop { 500 500 } ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +M:: draw-gadget* ( GADGET -- ) + origin get + [ + T{ rgba f 1 1 1 0.4 } \ fill-color set ! White, with some transparency + T{ rgba f 0 0 0 0 } \ stroke-color set ! no stroke + + black gl-clear + + GADGET points>> [ dot ] each-percent + ] + with-translation ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +: trails-gadget ( -- ) + + new-gadget + + 300 point-list >>points + + t >>clipped? + + dup start-trails-thread ; + +: trails-window ( -- ) [ trails-gadget "Trails" open-window ] with-ui ; + +! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +MAIN: trails-window \ No newline at end of file