-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwo-squares-a.py
More file actions
58 lines (48 loc) · 1.77 KB
/
two-squares-a.py
File metadata and controls
58 lines (48 loc) · 1.77 KB
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
import cmath
import svg
from jigsaw import along
R = 0.6
RHO = 0.15
def corner(center: complex, direction: complex, s: svg.SVG) -> svg.Path:
A = center
B = center + direction * R
C = center + direction * R * cmath.exp(1j * cmath.pi / 4)
D = center + direction * R * cmath.exp(2j * cmath.pi / 4)
path = svg.Path(A)
path.line(B)
path.circular_tab(A, C, C, RHO, inwards=False)
path.circular_tab(A, D, D, RHO, inwards=False)
path.line(A)
return path
def edge(center: complex, direction: complex) -> svg.Path:
A = center
B = center + direction
C = center + direction * (-1j)
BA = along(B, A, R)
BC = along(B, C, R)
CB = along(C, B, R)
CA = along(C, A, R)
path = svg.Path(A)
path.line(BA)
path.circular_tab(B, BC, BC, RHO, inwards=False)
path.line(CB)
path.circular_tab(C, CA, CA, RHO, inwards=False)
path.line(A)
return path
with svg.SVG(0, 1.1, 700, 300, __file__) as s:
for i in range(4):
with s.transformation(shift=-1.5, rotate=90*i):
s.draw_path(edge(0, 1 + 1j), svg.COLORS[2*(i%2)])
s.draw_path(corner(1+1j, -1, s), svg.COLORS[2*(i%2)+1])
with s.transformation(shift=1+1j, rotate=-90):
s.draw_path(edge(0, 1+1j), svg.COLORS[0])
with s.transformation(shift=1-1j, rotate=90):
s.draw_path(edge(0, 1+1j), svg.COLORS[0])
with s.transformation(shift=2, rotate=-45):
s.draw_path(corner(0, -1, s), svg.COLORS[1])
with s.transformation(shift=0, rotate=180-45):
s.draw_path(corner(0, -1, s), svg.COLORS[1])
with svg.SVG(0, 1, 300, 300, __file__, "-corner") as s:
s.draw_path(corner(-.5j, 1, s), "black", "black", 0)
with svg.SVG(0, 1, 300, 300, __file__, "-edge") as s:
s.draw_path(edge(0, 1+1j), "black", "black", 0)