-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGolden_Triangle_Division.cfdg
More file actions
93 lines (83 loc) · 2.36 KB
/
Golden_Triangle_Division.cfdg
File metadata and controls
93 lines (83 loc) · 2.36 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Golden Triangle Division 黄金三角形分割
startshape gtd(5, 1, 0) [ ]
φ = (1 + sqrt(5)) / 2 // 黄金数
shape gtd(natural n, natural ft, natural tt) {
loop 5 [r 72] {
thin(n, ft, tt) [ flip 90 ]
thin(n, ft, tt) [ r 36 ]
}
}
// 細い二等辺三角形 辺の長さ比(φ:φ:1) 角度(π/5, 2π/5, 2π/5)
shape thin(natural n, natural ft, natural tt) {
if (n <= 0) {
draw_thin []
} else {
y1 = -φ * sin(72) // 360/5
r1 = 90 + 18
r2 = r1 + 36
s1 = 1 / φ
s2 = φ - 1
x2 = -s2 * cos(72)
y2 = -s2 * sin(72)
x3 = cos(72)
y3 = -sin(72)
r3 = -r1
if (tt == 0) {
// Thin_Small
thin(n -- 1, ft, 0) [ x -0.5 y y1 rotate r1 s s1 ] // T_L & T_S
fat(n -- 1, ft, 0) [ x x3 y y3 rotate r3 ] // T_S
} else {
// Thin_Large
thin(n -- 1, ft, 1) [ x -0.5 y y1 rotate r1 s s1 ] // T_L & T_S
thin(n -- 1, ft, 1) [ x -0.5 y y1 rotate r2 s s1 flip 90 ] // T_L
fat(n -- 1, ft, 1) [ x x2 y y2 s s2 rotate r1 flip 90 ] // T_L
}
}
}
// 太い二等辺三角形 辺の長さ比(1:1:φ) 角度(3π/5, π/5, π/5)
shape fat(natural n, natural ft, natural tt) {
if (n <= 0) {
draw_fat []
} else {
x1 = φ / 2
y1 = -sin(180/5)
r1 = -90 - 18
s1 = 1 / φ
x2 = -x1 + (φ - 1)
r2 = r1 - 36
s2 = 1 / (1+φ)
r3 = 180 - 36
x3 = s2 * cos(36)
y3 = -s2 * sin(36)
if (ft == 0) {
// Fat_Small
fat(n -- 1, 0, tt) [ x x2 y y1 rotate r2 s s1 ] // F_S, F_L
thin(n -- 1, 0, tt) [ x x1 y y1 rotate r1 s s1 flip 90 ] // F_S
} else {
// Fat_Large
fat(n -- 1, 1, tt) [ x x2 y y1 rotate r2 s s1 ] // F_S, F_L
thin(n -- 1, 1, tt) [ x x2 y y1 r r3 s s2 flip 90 ] // F_L
fat(n -- 1, 1, tt) [ x x3 y y3 s s1 flip 90 ] // F_L
}
}
}
// 細い二等辺三角形を描きます
// 二等辺三角形の頂点を原点(0,0)とします
// 下(y軸負方向)に底辺を描きます
path draw_thin {
MOVETO(0, 0) // (0)
LINETO(-0.5, -φ * sin(360/5)) // (1)
LINETO(+0.5, -φ * sin(360/5)) // (2)
CLOSEPOLY()
FILL()[ sat 1 b 1 ]
}
// 太い二等辺三角形を描きます
// 二等辺三角形の頂点を原点(0,0)とします
// 下(y軸負方向)に底辺を描きます
path draw_fat {
MOVETO(0, 0) // (0)
LINETO(-φ/2, -sin(180/5)) // (1)
LINETO(+φ/2, -sin(180/5)) // (2)
CLOSEPOLY()
FILL()[ hue 45 sat 1 b 1 ]
}