forked from SolidCode/SolidPython
-
Notifications
You must be signed in to change notification settings - Fork 21
/
07-libs-bosl2.py
executable file
·64 lines (53 loc) · 1.72 KB
/
07-libs-bosl2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#! /usr/bin/env python
from solid2.extensions.bosl2 import *
from solid2.extensions.bosl2 import metric_screws
#basic stuff
def bolt():
return metric_screws.metric_bolt(size=20, headtype='hex', l=40)
def extrude_along_path():
path = [ [0, 0, 0], [33, 33, 33], [66, 33, 40], [100, 0, 0], [150,0,0] ]
return circle(r=10, _fn=6).path_extrude(path)
def heightfield_test():
def get_data():
from math import sqrt,sin
data = []
for y in range(50):
yrow = []
data.append(yrow)
for x in range(50):
yrow.append(sin(sqrt((y-25)**2+(x-25)**2)))
return data
return heightfield(size=[100,100], bottom=-1, data=get_data())
#a little bit more complicated stuff
def bosl_diff():
#openscad example from bosl2 wiki:
#diff()
# cuboid(50) {
# tag("remove") attach(TOP) sphere(d=40);
# tag("keep") attach(CTR) cylinder(h=40, d=10);
# }
return \
diff() (
cuboid(50) (
tag("remove") (attach(TOP) (sphere(d=40))),
tag("keep") (attach(CTR) (cylinder(h=40, d=10)))
)
)
def bosl_diff2():
#openscad example from bosl2 wiki:
#diff()
# cuboid(50) {
# tag("remove") attach(TOP) sphere(d=40);
# tag("keep") attach(CTR) cylinder(h=40, d=10);
# }
return \
cuboid(50) (
sphere(d=40).attach(TOP).tag("remove"),
cylinder(h=40, d=10).attach(CTR).tag("keep")
).diff()
assembly = ~extrude_along_path().bounding_box() +\
extrude_along_path().recolor("purple") +\
bosl_diff2().back(100) +\
bolt().left(100) +\
heightfield_test().fwd(100)
assembly.save_as_scad()