I got it working! The plot demo application has a slideshow feature that
updated the plot in place without flickering. Here's the working code:


NB. -------------------------------------------------

NB. animated sine plot in J

NB. by michal wallace (http://tangentstorm.com/)

NB. free for use under the MIT license

NB. -------------------------------------------------


load'plot'

coinsert each 'jgl2'; 'jzplot'


pc =: 'w0' NB. name of parent control (window)

pn =: 'animated plot' NB. parent name (window title)

cc =: 'g0' NB. name of child control (isidraw canvas)

wh =: 720 200 NB. width and height of the window


n =: 0x NB. tick counter

s =: 0$0 NB. series to plot


update =: verb define NB. build a series for a sine wave

s =: 1 o. (n =: n + 1) + 0.1 * i: 100

)


render =: verb define NB. put pd commands here

pd 'frame 1; axes 1 1; labels 0 0;'

pd 'color red'

pd s

)


NB. -------------------------------------------------

NB. everything below here is pretty much boilerplate

NB. ------------------------------------------------


trap_z_ =: verb define NB. halt timer to avoid infinite modal error msg
death loop

wd 'timer 0'

smoutput LF,(13!:12''),'timer stopped.' [ wd 'timer 0'

)


signal_jzplot_=:13!:8&12 [ trap


3 : 0'' NB. create the window if it doesn't exist

if. -. wdisparent pc do.

wd 'pc ',pc,' closeok; pn "',pn,'";'

wd 'minwh ',(":wh),'; cc ',cc,' isidraw flush;'

wd 'pshow; pcenter;'

end.

)


to_pc =: verb define NB. choose where to draw pd commands

wd 'psel ', PForm_jzplot_=: pc

PFormhwnd_jzplot_ =: wd 'qhwndp'

PIdhwnd_jzplot_ =: wd 'qhwndc ', PId_jzplot_=: cc

glclear''

pd 'reset ',pc

)


paint =: verb define NB. repaint current window on demand

glpaint @ ppaint''

)


step =: verb define NB. animation engine, with error trap

try. paint render to_pc [ update''

catch. trap'' end.

)


sys_timer_z_ =: step_base_

wd 'timer 100' NB. set to 0 to stop the timer



On Sat, Aug 10, 2019 at 2:52 PM Michal Wallace <michal.wall...@gmail.com>
wrote:

> Hey all,
>
>
> I'm experimenting with animation in J for a new video...
>
>
> I'm use the wd timer to make an animated plot, and it mostly works, but
> the window itself disappears and reappears on every frame, causing an
> unwatchable flicker effect.
>
>
> How can I keep the plot window from flickering, or pipe the output to an
> isidraw in my own window?
>
>
> Here's a simple sine wave example to demonstrate the problem. (Running in
> j807 / jqtide)
>
>
>
> NB. warning: put this code in the j editor before running, or
>
> NB. you may wind up having to kill your j session...
>
>
> load'plot'
>
>
> step =: 0x
>
> sys_timer_z_ =: 3 : 0
>
> n =. step_base_ =: step_base_ + 1
>
> NB. plot wants to focus on the window, and if you don't use
>
> NB. wd to refocus on the editor, your session will become unusable.
>
> wd 'sm focus edit' [ plot 1 o. 8 %~ n + i:32
>
> )
>
>
> wd'timer 50' NB. change this to 0 to stop the timer
>
>
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to