! Animate a gnuplot graph
! =======================

USE gnuplot
REAL g(-20..20,-20..20) ! declare a 2D array with negative lower bounds
OPENGRAPH           ! open a clean graphics window 
! uncomment the following line to record rather than display your animation
! OPENMOVIE "myanimation.mp4"  ! requires ffmpeg to be installed

set zrange [-1:1]   ! "set" commands are passed to gnuplot unchanged
! zrange must be set or it will change from one image to another
LOOP FOR t=0. TO 200 BY 0.3   ! LOOP can have a REAL index
  amp=SIN(t)        ! time-varying amplitude
  DO g(ix,iy)=amp*EXP{-[(0.1*ix)^2+(0.1*iy)^2]/2} FOR ALL ix,iy
  ! a compact LOOP form, tested at the end
  ! alternating the three kinds of brackets improves clarity
  SPLOT g           ! plot 2D array as a surface
REPEAT