Another approach - a bit more involved, but which would allow for user
interaction of various sorts that a tight loop does not, would be to
not use a tight loop but instead use a timer:

This requires making some things global (or - use a numbered locale to
hold them if you need that kind of isolation - but this example does
not). Something like this (assuming the other code you posted in this
thread):

dapoly=: 3 : 0 NB. Show polygon
  0 0 0 dapoly y
:
  if. (1=$$x) do. X=:(#y)$,:x else. X=.x end.
  Y=:x:^:_1 SC 2{."1 y
  K=:0
  wd 'timer ',":<.1000*DELAY
  (sys_timer_z_=:painter_base_)''
)

painter=:3 :0
  if.K<#Y do.
    wd 'psel ',WIN_nam
    glclear ''
    dfillcolor K{X
    glpolygon ,K{Y
    glpaintx ''
    K=:>:K
  else.
    wd'timer 0'
  end.
)

The downside of using the timer is that when it goes wrong you might
have to restart your J session. And if you do not care about using the
command line during the animation this approach might be overkill.

Thanks,

-- 
Raul

On Sun, Apr 26, 2015 at 7:03 PM, bill lam <[email protected]> wrote:
> you are running a tight loop. add
>
> wd'msgs'
>
> before the line
>
> delay DELAY
> On Apr 27, 2015 6:52 AM, "Cliff Reiter" <[email protected]> wrote:
>
>> You need some access to gl2.ijs too, for for the sake of completeness"
>>
>> coinsert 'jgl2'
>>
>> require 'trig gl2'
>>
>>
>> dawin=: 3 : 0
>>
>> 0 0 1 1 1 dawin y
>>
>> :
>>
>> 'a c b d e'=.x
>>
>> SC=:WIN_WH&*@((-&(a,d)) %((b-a),c-d)"1)"1
>>
>> sz=.":WIN_WH
>>
>> PN=.y,'; Animation window bounds are x: ',(":a),' to ',(":b),' y:
>> ',(":c),' to ',":d
>>
>> nx_WIN ''
>>
>> z=.'pc ',WIN_nam,' closeok;pn "',PN,'";minwh ',sz,' ;cc g isidraw;'
>>
>> wd z,';pshow;'
>>
>> glclear''
>>
>> DELAY=:e
>>
>> )
>>
>>
>> dfillcolor=: 3 : 0 NB. Start Fill Color
>>
>> wd 'psel ',WIN_nam
>>
>> if. _1 e.y do. glbrushnull ''
>>
>> else. glrgb y
>>
>> glbrush''
>>
>> end.
>>
>> )
>>
>>
>> NB. ------------------------------------------------
>>
>> NB. dapoly v Displays animated list of 2-D polygons
>>
>> dapoly=: 3 : 0 NB. Show polygon
>>
>> 0 0 0 dapoly y
>>
>> :
>>
>> if. (1=$$x) do. X=.(#y)$,:x else. X=.x end.
>>
>> Y=.x:^:_1 SC 2{."1 y
>>
>> wd 'psel ',WIN_nam
>>
>> k=.0
>>
>> while. k<#y do.
>>
>> glclear ''
>>
>> dfillcolor k{X
>>
>> glpolygon ,k{Y
>>
>> glpaintx ''
>>
>> delay DELAY
>>
>> k=.>:k
>>
>> end.
>>
>> )
>>
>>
>> nx_WIN=:3 : 0
>>
>> try. WIN_num=: WIN_num + 1 catch. WIN_num=: 0 end.
>>
>> WIN_nam=:'p',": WIN_num
>>
>> )
>>
>>
>> delay=:6!:3
>>
>> WIN_WH=:500 500
>>
>> sq=:#: 0 1 3 2
>>
>> _2 _2 2 2 0.1 dawin 'rot'
>>
>> rot=:(cos,sin),:-@sin,cos
>>
>> R=:(rot 1r40p1)&(+/ . *)"1
>>
>> $pl=:R^:(i.120) sq
>>
>> 0 255 0 dapoly pl
>>
>>
>>
>>
>> On 4/26/2015 6:47 PM, Cliff Reiter wrote:
>>
>>> nx_WIN=:3 : 0
>>>
>>> try. WIN_num=: WIN_num + 1 catch. WIN_num=: 0 end.
>>>
>>> WIN_nam=:'p',": WIN_num
>>>
>>> )
>>>
>>>
>>>
>>> On 4/26/2015 5:54 PM, Raul Miller wrote:
>>>
>>>> I get a value error on nx_WIN
>>>>
>>>> Thanks,
>>>>
>>>>
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>
>>>
>>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to