! rtliss
!
! $Revision: 1.1 $
! $Modtime:   24 Jun 1994 18:27:54  $
!
! Generates realtime Lissajous figures: (x,y) plots where
!	x = sin(at) * cos(bt)
!	y = sin(at) * sin(bt)
! Multiplies a and b by 2pi so the frequencies are irrational and the figures
! don't look too regular (how dull!)--unless <rational> is Yes.  Just for fun!
!
! Notice the tweeking of pipe sizes /PS=n , and transfer lengths /TL=n
! 

startmacro/xpipe/setup/quiet  D:a  D:b  L:pts  A:rational 

local freqa ampla freqb amplb twopi item
res p_label "MYLISS"
if rational neqss "Y" then
  calc twopi 1 atan 8 *
  calc a a twopi *
  calc b b twopi *
endif
sincosine/tl=1000/ctag=(1:freqb,2:amplb) ,,,   1 b 0 pts 0 1 _b
sincosine/tl=1000/ctag=(1:freqa,2:ampla) _a ,, 1 a 0 pts 0 1
multiply/tl=1000  _a _b _c in
noop/rt _c(xd=2e-5) _d
xrtplot/xs=2/nospecs/xcnt=2/mtag=(x:freqb,y:freqa) &
  _d(fs=1000) -1.1 1.1 ri ,, 75
xrtdisplay/xs=3 freqa/"A Frequency" ampla/"A Amplitude" &
                freqb/"B Frequency" amplb/"B Amplitude"
endmacro
!
startcontrols

XCONTROL/lab=M1 MENU ITEM 0 &
  "OPTIONS;GRID,POP MENU,ZOOM,UNZOOM,FLIP,RANDOM,SAVE,RECALL,QUIT"
XCONTROL/name="Y Frequency" DVAL ,, freqa  1. -1. .01 t:freqa
XCONTROL/name="X Frequency" DVAL ,, freqb  1. -1. .01 t:freqb

label M1
if ITEM eq 1
  xcall/xs=2 send string "MSEG"
elseif ITEM eq 2
  xcall/xs=2 send keypress M 100 100
  loop 20
    pause .1
    xcall/xs=2 send keypress DOWN
  endloop
  xcall/xs=2 send buttonpress 3
elseif ITEM eq 3
  res P_L 400
  res P_T 400
  xcall/xs=2 send buttonpress 1 P_L P_T
  loop 4 P_S
    xcall/xs=2 send motionnotify ,, P_L+(P_S*50) P_T+(P_S*50)
    pause .2
  endloop
  xcall/xs=2 send buttonrelease 1 P_L+(P_S*50) P_T+(P_S*50)
elseif ITEM eq 4
  xcall/xs=2 send buttonpress 3 100 100
elseif ITEM eq 5
  calc p_temp freqb
  calc freqb freqa
  calc freqa p_temp
elseif ITEM eq 6
  calc freqb random 2 *
  calc freqa random 2 *
elseif ITEM eq 7
  xcall PROMPT P_LABEL P_LABEL "Figure Name: " 20
  res ^{P_LABEL}_A freqa
  res ^{P_LABEL}_B freqb
elseif ITEM eq 8
  xcall PROMPT P_LABEL P_LABEL "Figure Name: " 20
  if ^{P_LABEL}_A rexist
    res freqa ^{P_LABEL}_A
    res freqb ^{P_LABEL}_B
  else
    xcall MESSAGE "Results for figure ^P_LABEL not found" -1.0
  endif
elseif ITEM eq 9
  envir set break 1
endif
return

endcontrols
