Menu


Links

Contact me

Karsten Ahnert
Institut für Physik und Astronomie
Universität Potsdam
Karl-Liebknecht-Strasse 24/25
14476 Potsdam-Golm
Germany

Tel. +49 331 9775986

Animations with Gnuplot

An easy way to create an animation in an application is gnuplot. It is extremly easy to use. Take the following example, a linear oscillator:

#include <iostream>
#include <cmath>

#define tab "\t"

using namespace std;

int main(int argc,char **argv)
{
    for(double t=0;t<=100*M_PI;t+=M_PI/512.0)
    {
        cout<<"p [-1.5:1.5][-1.5:1.5] ′-′ ps 2"<<endl;
        cout<<sin(t)<<tab<<cos(t)<<endl<<′e′<<endl<<flush;
        // the next line slows down the animation
        for(int i=0;i<5000000;i++);
    }
    return 0;
}

Compile this little program and pipe the output into gnuplot:

g++ gp_circle.cc
./a.out | gnuplot

Thats all! Here is another example: The animated Lorenz attractor.