Starting from ctioga2 version 0.9, you can use the companion script ct2-make-movie to automatically generate movies from a ctioga2 command file. This new method is much simpler and more powerful than the old one, which is still described there. It relies on ffmpeg for encoding.

First example: diffusion of a gaussian concentration profile

Let’s first try to make a movie of the diffusion of a gaussian concentration profile over time.

ct2-make-movie runs ctioga2 on a command file repetitively, each time with a different value to the arg variable. We’ll assume that the variable arg holds a certain value between 1 and 50 (it will be our time). Let’s first plot the concentration at the time arg:

arg ?= 1.5
math /xrange -5:5
yrange 0:1.1
plot "1/($(arg))**0.5 * exp(-x**2/$(arg))"

In this file, we use the arg ?= 1.5 syntax that defines the variable arg unless it is already defined, as will be the case when called by ct2-make-movie. Then, we just run ct2-make-movie on this file, using the syntax 1..50:200 to mean that the arg variable will go from 1 to 50 in 200 steps:

ct2-make-movie -r 9cmx7cm -t movie-1.mp4 \
    -t -t movie-1.ogg \
    -p movie-1.ct2 1..50:200

Download files: MOV MP4 OGG

The -p option triggers the use of pdftoppm for rasterization of PDF files, which is significantly faster than that from ImageMagick. The -r 9cmx7cm option has the same meaning as for ctioga2: it selects the target page size, just like page-size, and changes the target resolution and aspect ratio. The -t movie-1.mp4 bit is here to give the output file name (and the container format, too). It is possible to write several -t options in case one wants to encode to several different files at once. We take advantage of this option to provide different file formats.

Second part: doing a bit better

While the previous video does the job, let’s take advantage of some features of ctioga2 to make it a little nicer. First of all, it would be nice to display the time on each frame. While at first, just displaying $(arg) would seem like a good idea, you’ll get something like 38.18090452261306 which will be both too long and much too annoying. The solution is to use eval and Ruby’s sprintf. We have furthermore decorated the graph below with axis labels and a gray line at the x = 0 level.

arg ?= 38.18090452261306
math /xrange -5:5
yrange -0.1:1.1
ylabel "Concentration"
xlabel "Position"
time = $(eval "sprintf '%.1f', $(arg)")
draw-text -4.5,0.8 '$t = '$(time)'$' /justification=left
draw-line -5,0 5,0 /color=Gray /style=Dashes
plot "1/($(arg))**0.5 * exp(-x**2/$(arg))"

Running ct2-make-movie this way gives the following movies.

ct2-make-movie -r 9cmx7cm -t movie-2.mp4 \
    -t -t movie-2.ogg \
    -p movie-2.ct2 1..50:200

Download files: MOV MP4 OGG

Latest news

ctioga2 version 0.14.1 is out

Release 0.14.1 of ctioga2 fixes a crash at startup with Ruby 2.3