-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathexample.py
46 lines (38 loc) · 1.09 KB
/
example.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
import numpy, svg3d, pyrr, math
def get_octahedron_faces():
f = math.sqrt(2.0) / 2.0
verts = numpy.float32(
[(0, -1, 0), (-f, 0, f), (f, 0, f), (f, 0, -f), (-f, 0, -f), (0, 1, 0)]
)
triangles = numpy.int32(
[
(0, 2, 1),
(0, 3, 2),
(0, 4, 3),
(0, 1, 4),
(5, 1, 2),
(5, 2, 3),
(5, 3, 4),
(5, 4, 1),
]
)
return 15.0 * verts[triangles]
def generate_svg(filename):
view = pyrr.matrix44.create_look_at(
eye=[50, 40, 120], target=[0, 0, 0], up=[0, 1, 0]
)
projection = pyrr.matrix44.create_perspective_projection(
fovy=15, aspect=1, near=10, far=200
)
camera = svg3d.Camera(view, projection)
style = dict(
fill="white",
fill_opacity="0.75",
stroke="black",
stroke_linejoin="round",
stroke_width="0.005",
)
mesh = svg3d.Mesh(get_octahedron_faces(), style=style)
view = svg3d.View(camera, svg3d.Scene([mesh]))
svg3d.Engine([view]).render(filename)
generate_svg("octahedron.svg")