The resulting position animation file
pos.gif

Make a gif-animation of a set of node positions as easy as pie using Gnuplot 4.2.

First you need a text-file with node positions and a time stamp for each position, let’s call it pos.txt:
Time: 0.0 router_ID: 0 XPOS: 700.1618781885769 YPOS: 31.944845349539474 ZPOS: 0.0
Time: 0.0 router_ID: 1 XPOS: 1040.4893413002778 YPOS: 100.75630974569457 ZPOS: 0.0
...

Next, we need to create a gnuplot script file pos.gp that can contain the following code:
a=a+2 ;# If your time stepping is less, change the incrementation here.
graph = sprintf("Time: %d s",a) ;# A time counter
plot './pos.txt' using 6:($2==a ? $8 : 1/0):(sprintf("%d",$4)) with labels offset 0,0.6 title graph, './pos.txt' using 6:($2==a ? $8 : 1/0):(sprintf("%d",$4)) with points lc rgb "blue" pt 6 notitle
pause 0
if (a<328) reread ;# We reread the script until the end of the pos.txt file. Change the number as wanted.

And finally, we create a bash script file pos.sh which runs the gnuplot script:
touch tmp.tmp; #Making sure there is something there before we delete it.
rm tmp.tmp;
t="reset;" ;# Entering the commands into a text string. We'll run it later.
t="$t set term gif animate medium transparent opt delay 50 size 640,480 xffffff;" ;# Check out other options in the gnuplot manual.
t="$t set xrange [0:1500];" ;# Your dimensions may vary
t="$t set yrange [0:300];" ;# Your dimensions may vary
t="$t set output 'pos.gif';" ;# The output gif file
t="$t a=-2;" ;# We need to start the counter at 0 minus the increment in pos.gp.
t="$t load 'pos.gp';"

echo $t >> tmp.tmp;
gnuplot tmp.tmp;

rm tmp.tmp;

All that is left now is to run the pos.sh file with the command (Remember to make it executable!)
./pos.sh

Make sure you open the final gif-file in a browser, as the result may be less than optimal with Ubuntu’s or other viewers.

Thanks to Lars Landmark for the challenge and the pos.txt file.

Advertisements