1+ #! /usr/bin/python
2+ # -*- coding: UTF-8 -*-
3+ from __future__ import division
4+ import os , sys , re
5+
6+ from solid import *
7+ from solid .utils import *
8+
9+ def my_animate ( _time = 0 ):
10+ # _time will range from 0 to 1, not including 1
11+ rads = _time * 2 * 3.1416
12+ rad = 15
13+ c = translate ( [rad * cos (rads ), rad * sin (rads )])( square ( 10 ))
14+
15+ return c
16+
17+ if __name__ == '__main__' :
18+ out_dir = sys .argv [1 ] if len (sys .argv ) > 1 else os .curdir
19+ file_out = os .path .join ( out_dir , 'animation_example.scad' )
20+
21+ print "%(__file__)s: SCAD file written to: \n %(file_out)s" % vars ()
22+
23+ # To animate in OpenSCAD:
24+ # - Run this program to generate a SCAD file.
25+ # - Open the generated SCAD file in OpenSCAD
26+ # - Choose "View -> Animate"
27+ # - Enter FPS (frames per second) and Steps in the fields
28+ # at the bottom of the OpenSCAD window
29+ # - FPS & Steps are flexible. For a start, set both to 20
30+ # play around from there
31+ scad_render_animated_file ( my_animate , # A function that takes a float argument in [0,1)
32+ # and returns an OpenSCAD object
33+ steps = 20 , # Number of steps to create one complete motion
34+ back_and_forth = True , # If true, runs the complete motion
35+ # forward and then in reverse,
36+ # to avoid discontinuity
37+ filepath = file_out , # Output file
38+ include_orig_code = True ) # Append SolidPython code
39+ # to the end of the generated
40+ # OpenSCAD code.
41+
42+
0 commit comments