This repository has been archived by the owner on Aug 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
penrose-gen.tex
356 lines (340 loc) · 11.3 KB
/
penrose-gen.tex
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
% via
% <http://tex.stackexchange.com/questions/61437/penrose-tiling-in-tikz/61623#61623>
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
% phi = golden ratio = (1+sqrt(5))/2
% invphi = 1/phi
% n: number of decompositions left to do
% ver: starting vertex
% angle: direction of first edge
% len: lenght of first edge
% rot: sense of rotation (0 => anticlockwise, 1 => clockwise)
\pgfmathsetmacro{\invphi}{2/(1+sqrt(5))}
% default styles
\tikzset{
% borders style
penrose line/.style={draw=black,line join=round},
% semikites and semidarts styles
penrose clockwise semikite/.style={penrose line},
penrose anticlockwise semikite/.style={penrose line},
penrose clockwise semidart/.style={penrose line},
penrose anticlockwise semidart/.style={penrose line},
% kites and darts styles
penrose kite/.style={penrose line},
penrose dart/.style={penrose line},
% the three paths (and the three corresponding reverse paths)
penrose common/.style={},
penrose path 1/.style={penrose common},
penrose path 2/.style={penrose common},
penrose path 3/.style={penrose common},
penrose rev path 1/.style={penrose common},
penrose rev path 2/.style={penrose common},
penrose rev path 3/.style={penrose common},
}
\newcommand\penrosedrawclockwisesemikite[3]{% ver, angle, len
% semikite (clockwise)
\path (#1) +(#2:#3) coordinate (#1-b) +(#2-36:#3) coordinate (#1-c);
\path[penrose anticlockwise semikite] (#1)
to[penrose path 1] (#1-b)
to[penrose path 2] (#1-c)
to[penrose path 3] (#1);
}
\newcommand\penrosedrawanticlockwisesemikite[3]{% ver, angle, len
% semikite (anticlockwise)
\path (#1) +(#2:#3) coordinate (#1-b) +(#2+36:#3) coordinate (#1-c);
\path[penrose clockwise semikite] (#1)
to[penrose path 1] (#1-b)
to[penrose path 2] (#1-c)
to[penrose path 3] (#1);
}
\newcommand\penrosesemikite[5]{% n, ver, angle, len, rot
\ifnum#1=0 % draw or recursive decomposition ?
\ifnum#5=1 % anticlockwise or clockwise ?
\penrosedrawclockwisesemikite{#2}{#3}{#4}
\else
\penrosedrawanticlockwisesemikite{#2}{#3}{#4}
\fi
\else
{
% decomposition (semikite => 2 semikites and 1 semidart)
\edef\dep{#1}
\edef\ver{#2}
\edef\angle{#3}
\edef\len{#4}
\edef\rot{#5}
\pgfmathtruncatemacro{\n}{\dep-1}
\edef\namex{\ver\n}
\pgfmathsetlengthmacro{\newlen}{\len*\invphi}
\ifnum#5=1 % anticlockwise or clockwise ?
\path (\ver) ++(\angle-36:\len) coordinate (\namex);
\pgfmathtruncatemacro{\newanglea}{mod(\angle+108,360)}
\penrosesemikite{\n}{\namex}{\newanglea}{\newlen}{1}
\penrosesemikite{\n}{\namex}{\newanglea}{\newlen}{0}
\penrosesemidart{\n}{\ver}{\angle}{\newlen}{1}
\else
\path (\ver) ++(\angle+36:\len) coordinate (\namex);
\pgfmathtruncatemacro{\newanglea}{mod(\angle-108,360)}
\penrosesemikite{\n}{\namex}{\newanglea}{\newlen}{0}
\penrosesemikite{\n}{\namex}{\newanglea}{\newlen}{1}
\penrosesemidart{\n}{\ver}{\angle}{\newlen}{0}
\fi
}
\fi
}
\newcommand\penrosedrawkite[3]{% ver, angle, len
% kite (current clockwise semikite + opposite anticlockwise semikite)
\path (#1)
+(#2+36:#3) coordinate (#1-b)
+(#2:#3) coordinate (#1-c)
+(#2-36:#3) coordinate (#1-d);
\pgfmathparse{0.9*rnd+0.3}
\definecolor{MyColor}{rgb}{\pgfmathresult,\pgfmathresult,\pgfmathresult}
\path[penrose kite] (#1)
to[penrose path 1] (#1-b)
to[penrose rev path 2] (#1-c)
to[penrose path 2] (#1-d)
to[penrose rev path 1] (#1);
}
\newcommand\penrosekite[5]{% n, ver, angle, len, rot
\ifnum#1=0 % draw or recursive decomposition ?
\ifnum#5=1 % draw kite if current semikite is clockwise
\penrosedrawkite{#2}{#3}{#4}
\fi
\else
{
% decomposition (semikite => 2 semikites and 1 semidart)
\edef\dep{#1}
\edef\ver{#2}
\edef\angle{#3}
\edef\len{#4}
\edef\rot{#5}
\pgfmathtruncatemacro{\n}{\dep-1}
\edef\namex{\ver\n}
\pgfmathsetlengthmacro{\newlen}{\len*\invphi}
\ifnum#5=1 % anticlockwise or clockwise ?
\path (\ver) ++(\angle-36:\len) coordinate (\namex);
\pgfmathtruncatemacro{\newanglea}{mod(\angle+108,360)}
\penrosekite{\n}{\namex}{\newanglea}{\newlen}{1}
\penrosekite{\n}{\namex}{\newanglea}{\newlen}{0}
\penrosedart{\n}{\ver}{\angle}{\newlen}{1}
\else
\path (\ver) ++(\angle+36:\len) coordinate (\namex);
\pgfmathtruncatemacro{\newanglea}{mod(\angle-108,360)}
\penrosekite{\n}{\namex}{\newanglea}{\newlen}{0}
\penrosekite{\n}{\namex}{\newanglea}{\newlen}{1}
\penrosedart{\n}{\ver}{\angle}{\newlen}{0}
\fi
}
\fi
}
\newcommand\penrosedrawclockwisesemidart[3]{
% semidart (clockwise)
\path (#1)
+(#2:#3) coordinate (#1-b)
+(#2-36:#3*\invphi) coordinate (#1-c);
\path[penrose anticlockwise semidart] (#1)
to[penrose path 3] (#1-b)
to[penrose path 2] (#1-c)
to[penrose path 1] (#1);
}
\newcommand\penrosedrawanticlockwisesemidart[3]{
% semidart (anticlockwise)
\path (#1)
+(#2:#3) coordinate (#1-b)
+(#2+36:#3*\invphi) coordinate (#1-c);
\path[penrose clockwise semidart] (#1)
to[penrose path 3] (#1-b)
to[penrose path 2] (#1-c)
to[penrose path 1] (#1);
}
\newcommand\penrosesemidart[5]{% n, ver, angle, len, rot
\ifnum#1=0 % draw or recursive decomposition ?
\ifnum#5=1 % anticlockwise or clockwise ?
\penrosedrawclockwisesemidart{#2}{#3}{#4}
\else
\penrosedrawanticlockwisesemidart{#2}{#3}{#4}
\fi
\else
{
% decomposition (semidart => 1 semikite and 1 semidart)
\edef\dep{#1}
\edef\ver{#2}
\edef\angle{#3}
\edef\len{#4}
\edef\rot{#5}
\pgfmathtruncatemacro{\n}{\dep-1}
\edef\namex{\ver\n}
\pgfmathsetlengthmacro{\newlen}{\len*\invphi}
\path (\ver) ++(\angle:\len) coordinate (\namex);
\ifnum#5=1 % anticlockwise or clockwise
\pgfmathsetmacro{\newanglea}{mod(\angle-144,360)}
\pgfmathsetmacro{\newangleb}{mod(\angle-36,360)}
\penrosesemidart{\n}{\namex}{\newanglea}{\newlen}{1}
\penrosesemikite{\n}{\ver}{\newangleb}{\newlen}{0}
\else
\pgfmathtruncatemacro{\newanglea}{mod(\angle+144,360)}
\pgfmathtruncatemacro{\newangleb}{mod(\angle+36,360)}
\penrosesemidart{\n}{\namex}{\newanglea}{\newlen}{0}
\penrosesemikite{\n}{\ver}{\newangleb}{\newlen}{1}
\fi
}
\fi
}
\newcommand\penrosedrawdart[3]{
% dart (current clockwise semidart + opposite anticlockwise semidart)
\path (#1)
+(#2:#3) coordinate (#1-b)
+(#2-36:#3*\invphi) coordinate (#1-c)
+(#2-72:#3) coordinate (#1-d);
\path[penrose dart] (#1)
to[penrose path 3] (#1-b)
to[penrose path 2] (#1-c)
to[penrose rev path 2] (#1-d)
to[penrose rev path 3] (#1);
}
\newcommand\penrosedart[5]{% n, ver, angle, len, rot
\ifnum#1=0 % draw or recursive decomposition ?
\ifnum#5=1 % draw dart if current semidart is clockwise
\penrosedrawdart{#2}{#3}{#4}
\fi
\else
{
% decomposition (semidart => 1 semikite and 1 semidart)
\edef\dep{#1}
\edef\ver{#2}
\edef\angle{#3}
\edef\len{#4}
\edef\rot{#5}
\pgfmathtruncatemacro{\n}{\dep-1}
\edef\namex{\ver\n}
\pgfmathsetlengthmacro{\newlen}{\len*\invphi}
\path (\ver) ++(\angle:\len) coordinate (\namex);
\ifnum#5=1 % anticlockwise or clockwise
\pgfmathsetmacro{\newanglea}{mod(\angle-144,360)}
\pgfmathsetmacro{\newangleb}{mod(\angle-36,360)}
\penrosedart{\n}{\namex}{\newanglea}{\newlen}{1}
\penrosekite{\n}{\ver}{\newangleb}{\newlen}{0}
\else
\pgfmathtruncatemacro{\newanglea}{mod(\angle+144,360)}
\pgfmathtruncatemacro{\newangleb}{mod(\angle+36,360)}
\penrosedart{\n}{\namex}{\newanglea}{\newlen}{0}
\penrosekite{\n}{\ver}{\newangleb}{\newlen}{1}
\fi
}
\fi
}
\newcommand\setveclength[5]{%
%\typeout{-#1-#2-#3-#4-}%
\pgfpointanchor{#2}{#3}
\pgfgetlastxy{\penrosexa}{\penroseya}
\pgfpointanchor{#4}{#5}
\pgfgetlastxy{\penrosexb}{\penroseyb}
\pgfmathparse{veclen(\penrosexb-\penrosexa,\penroseyb-\penroseya)}
\edef#1{\pgfmathresult}
}
\tikzset{
semipenrose sym fill/.style={
path picture={
\setveclength{\mylen}%
{path picture bounding box}{center}%
{path picture bounding box}{north west}
\pgfmathsetmacro{\len}{1.17*\mylen}
\begin{scope}[shift={(path picture bounding box.center)}]
\foreach \level in {0,...,4}{
\begin{scope}[rotate=\level*72+9]
\coordinate (a) at (0,0);
\penrosesemikite{#1}{a}{0}{\len pt}{0}
\penrosesemikite{#1}{a}{0}{\len pt}{1}
\end{scope}
}
\end{scope}
}
},
semipenrose fill/.style={
path picture={
\setveclength{\mylen}%
{path picture bounding box}{center}%
{path picture bounding box}{west}
\pgfmathsetmacro{\len}{1.33*\mylen}
\begin{scope}[shift={(path picture bounding box.center)},rotate=9]
\coordinate (a) at (-\len pt,0);
\path (a) +(36:2*\len pt) coordinate (b);
\path (a) +(-36:2*\len pt) coordinate (c);
\penrosesemidart{#1}{b}{36-180}{2*\len pt}{1}
\penrosesemikite{#1}{a}{0}{2*\len pt}{0}
\penrosesemikite{#1}{a}{0}{2*\len pt}{1}
\penrosesemidart{#1}{c}{180-36}{2*\len pt}{0}
\end{scope}
}
},
penrose sym fill/.style={
path picture={
\setveclength{\mylen}%
{path picture bounding box}{center}%
{path picture bounding box}{north west}
\pgfmathsetmacro{\len}{1.23*\mylen}
\begin{scope}[shift={(path picture bounding box.center)}]
\foreach \level in {0,...,4}{
\begin{scope}[rotate=\level*72+9]
\coordinate (a) at (0,0);
\penrosekite{#1}{a}{18}{\len pt}{0}
\penrosekite{#1}{a}{18}{\len pt}{1}
\end{scope}
}
\end{scope}
}
},
penrose fill/.style={
path picture={
\setveclength{\mylen}%
{path picture bounding box}{center}%
{path picture bounding box}{west}
\pgfmathsetmacro{\len}{2.38*\mylen}
\begin{scope}[shift={(path picture bounding box.center)},rotate=9]
\coordinate (a) at (-\len pt,0);
\path (a) +(36:2*\len pt) coordinate (b);
\path (a) +(-36:2*\len pt) coordinate (c);
\penrosedart{#1}{b}{36-180}{2*\len pt}{1}
\penrosekite{#1}{a}{0}{2*\len pt}{0}
\penrosekite{#1}{a}{0}{2*\len pt}{1}
\penrosedart{#1}{c}{180-36}{2*\len pt}{0}
\end{scope}
}
},
}
\usetikzlibrary{shapes.arrows}
\pgfmathsetlengthmacro{\len}{4cm}
\pgfmathtruncatemacro{\recurs}{5}
\begin{document}
\begin{tikzpicture}
\tikzset{
gray arrow/.style={
fill=gray,minimum height=.5cm,rotate=-90,
single arrow,single arrow head extend=1mm,
},
}
\tikzset{
% style for borders
line/.style={draw=white,rounded corners=0pt},
% styles for semikites and semidarts
penrose clockwise semikite/.style={fill=orange,line},
penrose anticlockwise semikite/.style={fill=orange!50!black,line},
penrose clockwise semidart/.style={fill=cyan!80,line},
penrose anticlockwise semidart/.style={fill=cyan!50,line},
% styles for kites and darts
penrose kite/.style={fill=red!75!black,line},
penrose dart/.style={fill=olive!75!white,line},
}
% example of semidarts and semikites
\begin{scope}[yshift=-2*\len]
\foreach \level in {0,...,7}{
\begin{scope}[rotate=\level*72]
\coordinate (a) at (0,0);
\penrosesemikite{\recurs}{a}{0}{\len}{0}
\penrosesemikite{\recurs}{a}{0}{\len}{1}
\end{scope}
}
\end{scope}
\end{tikzpicture}
\end{document}