    

 ## On this page

  

 

 # Automated image output 

 Last update: 16.07.2025 

This script shows how to do animated graphics. The animation will show the variation of a random field parameter ranging between -3 and 3. It will generate a series of 50 png images. They can be converted e.g. to an animated GIF using ImageMagick.

-- load example data:

sdbfile = sos.currentScriptPath() .. "/../lsdyna/metal_forming__eroded_elements/sos_demo.sdb"

local settings = sos.LoadDataBaseSettings(sdbfile);

sos.loadDataBase(sos.database(), settings);







-- define a vector of parameter values:

lb = -3

ub = 3

N = 50

ticks = tmath.ZeroMatrix(N,1)

for i=0, N//4 do

 ticks[i] = (ub+lb)/2 + (ub-lb)/2 * i/(N//4);

end

for i=N//4, (3*N)//4 do

 ticks[i] = (ub+lb)/2 + (ub-lb)/2 *(1 - (i-N//4)/(N//4) );

end

for i=(3*N)//4, N-1 do

 ticks[i] = (ub+lb)/2 + (ub-lb)/2 *( -1 + (i-(3*N)//4)/(N//4) );

end



print("ticks: ", ticks:Transpose());



-- define scene properties:

render_data = sos.AllRenderData();

render_data.contour_plot.data_type = sos.RenderData.ELEMENT_DATA

render_data.contour_plot.data_kind = sos.RenderData.RANDOM_FIELD

render_data.contour_plot.quantity_ident = "pstrain";

sos.sceneManager():setSceneData(render_data);

sos.sceneManager():setDefaultRotation();

--sos.sceneManager():setRotation(133.245, -0.5292, 0.442588, 0.723922);

sos.sceneManager():fit();

sos.sceneManager():setPaletteRange("CURRENT");

sos.sceneManager():setRulerVisibility(false);

sos.sceneManager():setLegendPosition("");

--sos.sceneManager():setLegendPosition("NE");



-- export values:

for i=0,ticks:Rows()-1 do

 local inputs = tmath.Matrix({{ ticks[i], 0, 0, 0, 0, 0, 0}} )

 sos.sceneManager():setSceneData( inputs );

 local filename = string.format("image%03d.png", i+1)

 sos.sceneManager():file(filename, 640, 480);

end



print("Terminate script with success.")