Skip to content

Commit 5c337ab

Browse files
committed
Added animation_example.py. Cleaned up run_all_examples.sh formatting
1 parent fcbbe95 commit 5c337ab

File tree

10 files changed

+56
-12
lines changed

10 files changed

+56
-12
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+

solid/examples/append_solidpython_code.py

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def show_appended_python_code():
1818

1919
a = show_appended_python_code()
2020

21-
print "%(__file__)s: SCAD file written to: \n%(file_out)s \n"%vars()
21+
print "%(__file__)s: SCAD file written to: \n%(file_out)s"%vars()
2222
# ================================================================
2323
# = include_orig_code appends all python code as comments to the
2424
# = bottom of the generated OpenSCAD code, so the final document

solid/examples/basic_geometry.py

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def basic_geometry():
4343

4444
a = basic_geometry()
4545

46-
print "%(__file__)s: SCAD file written to: \n%(file_out)s \n"%vars()
46+
print "%(__file__)s: SCAD file written to: \n%(file_out)s"%vars()
4747

4848
# Adding the file_header argument as shown allows you to change
4949
# the detail of arcs by changing the SEGMENTS variable. This can

solid/examples/basic_scad_include.py

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ def demo_scad_include():
1818

1919
a = demo_scad_include()
2020

21-
print "%(__file__)s: SCAD file written to: \n%(file_out)s \n"%vars()
21+
print "%(__file__)s: SCAD file written to: \n%(file_out)s"%vars()
2222

2323
scad_render_to_file( a, file_out)

solid/examples/bom_scad.py

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def assemble():
108108

109109
bom = bill_of_materials()
110110

111-
print "%(__file__)s: SCAD file written to: \n%(file_out)s \n"%vars()
111+
print "%(__file__)s: SCAD file written to: \n%(file_out)s"%vars()
112112
print bom
113113

114114
scad_render_to_file( a, file_out)

solid/examples/hole_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ def pipe_intersection_no_hole():
5252

5353
a = pipe_intersection_no_hole() + right( 45)(pipe_intersection_hole())
5454

55-
print "%(__file__)s: SCAD file written to: \n%(file_out)s \n"%vars()
55+
print "%(__file__)s: SCAD file written to: \n%(file_out)s"%vars()
5656
scad_render_to_file( a, file_out, file_header='$fn = %s;'%SEGMENTS, include_orig_code=True)
5757

solid/examples/path_extrude_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ def extrude_example():
5353

5454
a = extrude_example()
5555

56-
print "%(__file__)s: SCAD file written to: \n%(file_out)s \n"%vars()
56+
print "%(__file__)s: SCAD file written to: \n%(file_out)s"%vars()
5757
scad_render_to_file( a, file_out, include_orig_code=True)
5858

solid/examples/run_all_examples.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ if [ ! -e $COMPILED_EXAMPLES ];
77
fi
88

99
for py in *.py;
10-
do echo "===================================================";
11-
echo "python $py $COMPILED_EXAMPLES";
12-
python $py $COMPILED_EXAMPLES;
13-
echo "===================================================";
10+
do
11+
echo "===================================================";
12+
echo "python $py $COMPILED_EXAMPLES";
13+
python $py $COMPILED_EXAMPLES;
14+
echo "===================================================";
15+
echo
1416
done
1517

1618
# Note: mazebox example isn't included because it requires a

solid/examples/screw_thread_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def assembly():
2626

2727
a = assembly()
2828

29-
print "%(__file__)s: SCAD file written to: \n%(file_out)s \n"%vars()
29+
print "%(__file__)s: SCAD file written to: \n%(file_out)s"%vars()
3030

3131
scad_render_to_file( a, file_out, include_orig_code=True)
3232

solid/examples/sierpinski.py

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,5 @@ def sierpinski_3d( generation, scale= 1, midpoint_weight=0.5, jitter_range_vec=N
100100

101101

102102
file_out = os.path.join( out_dir, 'gasket_%s_gen.scad'%generations)
103-
print "%(__file__)s: SCAD file written to: \n%(file_out)s \n"%vars()
103+
print "%(__file__)s: SCAD file written to: \n%(file_out)s"%vars()
104104
scad_render_to_file( t, file_out)

0 commit comments

Comments
 (0)