Showing posts with label animation. Show all posts
Showing posts with label animation. Show all posts

Monday, April 2, 2012

New version of gnuplot makes iterations easy --- animation as an example

Gnuplot4.6 have been released on 2012.03.08. And some new features have been added. Among them, I think block-structured if/else/while/do is the most useful one. With this new feature, one can easily deal with loop. In this post I will talk about this new feature taking animation as an example. In a previous post, how to create a gif animation using gnuplot have been talked. And it seems a little complex. An extra file is needed. Here with this new feature in gnuplot4.6, the work can be done simply as follows:

reset
set term gif animate
set output "animate.gif"
n=24 #n frames
dt=2*pi/n
set xrange [0:4*pi]
set yrange [-1:1]
do for [i=0:n]{
  plot sin(x+i*dt)/(1. + i/12.) w l lw 1.5 title sprintf("t=%i",i)
}
set output
Animation using new fearute of gnuplot4.6
 



Thursday, September 22, 2011

Creating gif animation using gnuplot

Now the new version of gnuplot(gnuplot4.6) makes things much easier, you can refer to another of my posts for the new way.

Some times an animation makes thing much easier to be understood. When I was in middle school, I can not understand the propagation of wave well although the teacher took great effort to explain it to me. At last he show me an animation of propagating wave, at the instance i understand it. So can gnuplot create such a powerful thing? The answer is yes. Under gif terminal, if the animate option is selected, Gnuplot will thought each plot as a frame of an animation. Next is an example.
#We will plot sin(x+t) in this gif animation
reset
set term gif animate
set output "animate.gif"
n=24    #n frames
dt=2*pi/n
set xrange [0:4*pi]
i=0
load "animate.gnuplot"
set output
where file animate.gnuplot contain the following gnuplot commands:
plot sin(x+i*dt) w l lt 1 lw 1.5 title sprintf("t=%i",i)
i=i+1
if (i < n) reread
Note you can not use "plot for ..." to create an animation, because gnuplot will look it as a single plot and will only create a single frame. Run the script we get an animation as this.


Creative Commons License
Except as otherwise noted, the content of this page is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.