-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcarlson.py
158 lines (132 loc) · 4.18 KB
/
carlson.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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
from drawing import CE, CS, CW, CN, DEG90
from tiler import TileBase, rotations
class CarlsonTile(TileBase):
"""https://christophercarlson.com/portfolio/multi-scale-truchet-patterns/"""
class G(TileBase.G):
def __init__(self, wh, bgfg=None):
super().__init__(wh, bgfg)
# +--+--+--+--+-----+
# 0 wh1 wh3 wh
# wh6 wh2
self.wh1 = wh / 3
self.wh2 = wh / 2
self.wh3 = wh * 2 / 3
self.wh6 = wh / 6
def init_tile(self, ctx, g, base_color=None):
ctx.arc(0, 0, g.wh1, CS, CE)
ctx.arc(g.wh, 0, g.wh1, CW, CS)
ctx.arc(g.wh, g.wh, g.wh1, CN, CW)
ctx.arc(0, g.wh, g.wh1, CE, CN)
ctx.close_path()
ctx.set_source_rgba(*g.bgfg[0])
ctx.fill()
ctx.set_source_rgba(*g.bgfg[1])
ctx.translate(g.wh2, g.wh2)
ctx.rotate(DEG90 * self.rot)
ctx.translate(-g.wh2, -g.wh2)
def draw(self, ctx, wh: int):
...
class CarlsonSlash(CarlsonTile):
def draw(self, ctx, g):
ctx.arc(g.wh2, 0, g.wh6, CW, CE)
ctx.arc_negative(g.wh, 0, g.wh1, CW, CS)
ctx.arc(g.wh, g.wh2, g.wh6, CN, CS)
ctx.arc(g.wh, 0, g.wh3, CS, CW)
ctx.fill()
ctx.arc(0, g.wh2, g.wh6, CS, CN)
ctx.arc(0, g.wh, g.wh3, CN, CE)
ctx.arc(g.wh2, g.wh, g.wh6, CE, CW)
ctx.arc_negative(0, g.wh, g.wh1, CE, CN)
ctx.fill()
class CarlsonMinus(CarlsonTile):
def draw(self, ctx, g):
ctx.circle(g.wh2, 0, g.wh6)
ctx.fill()
ctx.arc(g.wh, g.wh2, g.wh6, CN, CS)
ctx.arc(0, g.wh2, g.wh6, CS, CN)
ctx.close_path()
ctx.fill()
ctx.circle(g.wh2, g.wh, g.wh6)
ctx.fill()
class CarlsonHalfMinus(CarlsonTile):
def draw(self, ctx, g):
ctx.circle(g.wh2, 0, g.wh6)
ctx.fill()
ctx.arc(g.wh, g.wh2, g.wh6, CN, CS)
ctx.arc(g.wh2, g.wh2, g.wh6, CS, CN)
ctx.close_path()
ctx.fill()
ctx.circle(g.wh2, g.wh, g.wh6)
ctx.fill()
ctx.circle(0, g.wh2, g.wh6)
ctx.fill()
class CarlsonFour(CarlsonTile):
def draw(self, ctx, g):
for x, y in [(g.wh2, 0), (g.wh, g.wh2), (g.wh2, g.wh), (0, g.wh2)]:
ctx.circle(x, y, g.wh6)
ctx.fill()
class CarlsonX(CarlsonTile):
def draw(self, ctx, g):
ctx.arc(g.wh2, 0, g.wh6, CW, CE)
ctx.arc_negative(g.wh, 0, g.wh1, CW, CS)
ctx.arc(g.wh, g.wh2, g.wh6, CN, CS)
ctx.arc_negative(g.wh, g.wh, g.wh1, CN, CW)
ctx.arc(g.wh2, g.wh, g.wh6, CE, CW)
ctx.arc_negative(0, g.wh, g.wh1, CE, CN)
ctx.arc(0, g.wh2, g.wh6, CS, CN)
ctx.arc_negative(0, 0, g.wh1, CS, CE)
ctx.fill()
class CarlsonPlus(CarlsonTile):
def draw(self, ctx, g):
ctx.arc(g.wh, g.wh2, g.wh6, CN, CS)
ctx.arc(0, g.wh2, g.wh6, CS, CN)
ctx.close_path()
ctx.fill()
ctx.arc(g.wh2, 0, g.wh6, CW, CE)
ctx.arc(g.wh2, g.wh, g.wh6, CE, CW)
ctx.close_path()
ctx.fill()
class CarlsonFrown(CarlsonTile):
def draw(self, ctx, g):
ctx.arc(g.wh2, 0, g.wh6, CW, CE)
ctx.arc_negative(g.wh, 0, g.wh1, CW, CS)
ctx.arc(g.wh, g.wh2, g.wh6, CN, CS)
ctx.arc(g.wh, 0, g.wh3, CS, CW)
ctx.fill()
ctx.circle(g.wh2, g.wh, g.wh6)
ctx.fill()
ctx.circle(0, g.wh2, g.wh6)
ctx.fill()
class CarlsonT(CarlsonTile):
def draw(self, ctx, g):
ctx.arc(g.wh2, 0, g.wh6, CW, CE)
ctx.arc_negative(g.wh, 0, g.wh1, CW, CS)
ctx.arc(g.wh, g.wh2, g.wh6, CN, CS)
ctx.arc(0, g.wh2, g.wh6, CS, CN)
ctx.arc_negative(0, 0, g.wh1, CS, CE)
ctx.fill()
ctx.circle(g.wh2, g.wh, g.wh6)
ctx.fill()
carlson_demo = (
CarlsonSlash(),
CarlsonMinus(),
#CarlsonHalfMinus(),
CarlsonFour(),
CarlsonX(),
CarlsonPlus(),
CarlsonFrown(),
CarlsonT(),
)
carlson_tiles = (
*rotations(CarlsonSlash, 2),
*rotations(CarlsonMinus, 2),
CarlsonFour(),
CarlsonX(),
CarlsonPlus(),
*rotations(CarlsonFrown, 4),
*rotations(CarlsonT, 4),
)
carlson_extra = (
*carlson_tiles,
*rotations(CarlsonHalfMinus, 4),
)