OpenSCAD User Manual/Examples Animation
This page is a part of the Other Features page
Simple harmonic motion
translate ([0, 0, 10*sin($t*360)]) sphere(2);
gives a sphere that oscillates between -10 and +10 on the Z-axis.
Rotation
rotate ([0, 0, $t*360]) square(5);
rotates a square around one corner around the Z-axis.To rotate the square about its middle, use:
rotate ([0, 0, $t*360]) square(5, center=true);
Part-rotation
All parts in an animation complete one cycle of motion in the same time, $t, jump back to zero, and start again. However, the cycles can be given different numbers of steps, to give the illusion of different speeds in the same animation. This can be used to animate meshing gears of different sizes.
rotate([0, 0, $t*360/17]) gear(teeth=17);
and
rotate([0, 0, -$t*360/31]) gear(teeth=31);
Circular orbit
rotate ([0, 0, $t*360]) translate ([10, 0]) square(5, center=true);
Circular orbit without rotation
rotate ([0, 0, $t*360]) translate ([9, 0]) rotate ([0, 0, -$t*360]) square(5, center=true);
Elliptical orbit
translate([10*sin($t*360), 20*cos($t*360)])
square(2, center=true); Note that with " translate", the object does not rotate.
Elliptical motion
e=10; rotate([0, 0, $t*360]) translate([e, 0]) rotate([0, 0, -$t*720]) square([2*e, 2], center=true);
If "Dump Pictures" is checked, then images are created in the same directory as the .scad file. The exported PNG files can be turned into a gif via command line:
convert -delay 10 -loop 0 *.png myimage.gif
where -delay 10 is the duration of each frame in milliseconds, and -loop 0 specifies the number of loops (0 = loop forever).
The Linux convert command is part of ImageMagick, which can also be installed on macOS and Windows. Additional parameters are possible for cropping and scaling.