Animations using Xmgrace

General procedure

  • The general idea is to write a program (program.exe) in any language (e.g., in C or Fortran) that prints comands of xmgrace together with points. In particular one uses the comands
    "@kill s1" - to kill set 1 when passing from frame to frame
    "@redraw" - to redraw everything
    "@sleep 1" - to make it sleep for 1 second (introduces delay)
  • The xmgrace nicely animates this file using the following comand:
    cat example.agr | xmgrace -pipe -noask -autoscale none -fixed 1200 800 -timestamp -nosafe -geometry 1200x1200
    It is of course also possible to run directly the program (see below):
    program.exe | xmgrace -pipe -noask -autoscale none -fixed 1200 800 -timestamp -nosafe -geometry 1200x1200
  • To generate an animated gif, one asks the Xmgrace to plot .png or .ps files of each frame. One example of such file is [example_print.agr] (check that the directory "fig/" exists).
  • In order to join them in a single gif file one should use a suited program, e.g., in linux usually one can use
    convert *.png animation.gif
  • The animation is now huge. You can optimize and introduce some different velocity of the frames using
    gifsicle -d 1 -O animation.gif -o animation_d20.gif

Example: mushroom billiard

  • All data seen in the animations are contained in files (the programs to generate the dynamics of the billiard is not included here).
    The (x,y) components of the trajectory at each instant are [trajectory.dat] and [trajectory2.dat].
    The frame of the mushroom table is at the file [frame.dat].
  • The program that reads these files and plots them inside Xmgrace comands was written in C and is given as [mus_grace.c]. It has the following entries
    sintaxe: mus.exe [points] [line] [frames] [file]
    points=[1 or 2] | line=1 yes, 0 no | frames=[1,10^5] file=trajectory
  • A typical command to animate with the grace would be thus
    ./mus.exe 2 1 300 trajectory | xmgrace -pipe -noask -autoscale none -fixed 1200 800 -timestamp -nosafe -geometry 1200x1200
  • This was condensed in the script <a href="anime_mus.exe"> anime_mus.exe</a> and the comand simplified thus to:
    ./anime_mus.exe 2 1 300 trajectory
  • To generate gif animator, uncomment the appropriate lines in the program "mus_grace.c" above and create the directory "fig/". Then use
    convert *.png animation.gif

Do yourself:

  • Compile mus_grace.c to mus.exe
    gcc -o mus.exe -lm mus_grace.c
  • Run the following command
    ./anime_mus.exe 2 1 300 trajectory
  • If you were successfull you should see on Xmgrace screen the animation to the right.
  • To generate the gif animation, uncomment the appropriate lines in the C program and follow the instructions above