Being a command-line tool, ctioga2 lends itself well to the generation of movies, provided you have the right tools to encode them. Here, we use convert, from the ImageMagick suite to convert the generated PDF to the appropriate YUV format, and ffmpeg to encode the actual video.

We’ll generate the graphs and encode them on the fly in a shell script.


We’ll use the diffusion equation as an exemple. Imagine that the shell variable $i contains an increasing integer, figuring the time. We can generate the ith image using the following code:

ctioga2 -r 6cmx6cm --math /xrange -5:5 \
  --yrange 0:1.1 \
  "1/(0.1*${i}+1)**0.5 * exp(-x**2/(0.1*${i}+1))"
  --name Diffusion

One converts the PDF file into a raw YUV stream using convert:

convert -density 150 Diffusion.pdf -alpha Remove \
  -resize 400x400 -depth 8 YUV:- 

This YUV stream is then fed to the following ffmpeg pipe:

ffmpeg -f rawvideo -r 25 -s 400x400 -i - Diffusion.avi


One wraps all with a few ameliorations into this script:

#! /bin/sh

    for i in $(seq 1 100); do
        name=$(printf "Diffusion_%04d" $i)
        ctioga2 -r 6cmx6cm --math /xrange -5:5 \
            --yrange 0:1.1 \
            "1/(0.1*${i}+1)**0.5 * exp(-x**2/(0.1*${i}+1))" \
            --name $name;
        convert -density 150 $name.pdf -alpha Remove \
            -resize $size \
            -depth 8 YUV:- 
) | ffmpeg -f rawvideo -r 25 -s $size -i - Diffusion.avi

This generates the following video. It generates numbered PDF files, but you could do without and reuse the same PDF over and over again, although that may make it difficult to debug if something goes wrong.

Latest news

ctioga2 version 0.14.1 is out

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