Home > Resources > Making Animation with Scilab > 12. Saving animation in GIF file
<< Prev | Next >>
Making Animation with Scilab

12. Saving animation in GIF file

It is convenient to save an animation in a GIF file because then the animation can be viewed easily without Scilab. We can easily create animated GIF files using "animated GIF creator" module available from ATOMS.

The "animated GIF creator" module can be installed on Scilab 6.0 or above by command atomsInstall("animaGIF").

Code 1 shows a Scilab script that saves the animation of a moving point of Section 3 in a GIF file. In order to get a desirable result, the time step (Time data) and "delay" parameter of animaGIF may have to be adjusted appropriately.

animation_point_animaGIF.sce
// animation_point_animaGIF.sce

clear; xdel(winsid());

// Create motion data
t = 0:0.01:1;    // Time data
x = sin(2*%pi*t); // Position data

// Draw initial figure
h_fig = figure;
h_fig.background = 8;
drawlater();
h_point = plot(x(1), 0, 'Marker', 'o', 'MarkerSize', 20,..
    'MarkerEdgeColor', 'blue', 'MarkerFaceColor', 'blue');
h_axes = gca();
h_axes.data_bounds = [-1.5, -1.5; 1.5, 1.5];

// Initiate animated GIF
outgif = 'animation_point_scilab.gif';
mdelete(outgif);
idGif = animaGIF(gcf(), outgif, 10, 0);

// Animation Loop
for i = 1:length(x)
    drawlater();
    h_point.data = [x(i), 0];
    drawnow();

    // Add snapshot to animated GIF
    idGif = animaGIF(gcf(), idGif);
end

// Close animated GIF
animaGIF(idGif);
Code 1: Scilab script that saves the animation of a moving point of Section 3 in a GIF file

Sponsor Link