-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy path039_network_koch.py
38 lines (30 loc) · 1.11 KB
/
039_network_koch.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
import math
from compas.artists import Artist
from compas.datastructures import Network
from compas.geometry import Point
from compas.geometry import Rotation
from compas.geometry import Vector
lsys = "A-A++A-A-A-A++A-A++A-A++A-A-A-A++A-A-A-A++A-A-A-A++A-A++A-A++A-A-A-A++A-A++A-A++A-A-A-A++A-A++A-A++A-A-A-A++A-A-A-A++A-A-A-A++A-A++A-A++A-A-A-A++A"
network = Network()
step = 1.
pt = Point(0, 0, 0)
v = Vector(1, 0, 0)
def draw(network, point, vector, s, step, last_node=None):
for c in s:
if c == 'A':
point = point + vector * step
a = network.add_node(x=point.x, y=point.y, z=point.z)
if last_node != None:
network.add_edge(last_node, a)
last_node = a
elif c == '-':
R = Rotation.from_axis_and_angle((0, 0, 1), math.radians(60))
vector.transform(R)
elif c == '+':
R = Rotation.from_axis_and_angle((0, 0, 1), math.radians(-60))
vector.transform(R)
draw(network, pt, v, lsys, step)
artist = Artist(network, layer='network')
artist.clear_layer()
artist.draw_nodes()
artist.draw_edges()