-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTIkzGeneratorSnakes.tex
243 lines (222 loc) · 8.1 KB
/
TIkzGeneratorSnakes.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
\documentclass[tikz]{standalone}
%\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{xcolor}
\ifluatex\usepackage{luacode}\fi
\usepackage{amssymb}
%\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{hyperref}
\usetikzlibrary{matrix,decorations.pathreplacing,calc,shapes,fit}
\usetikzlibrary{backgrounds}
\usepackage{mathrsfs}
\def\curlyG{\mathscr{G}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\colorzero}[1]{\color{gray}{#1}}
\newcommand{\colorone}[1]{\color{blue}{#1}}
%
\pgfkeys{tikz/mymatrixbrace/.style={decorate,thick}}
\ifluatex
\begin{luacode*}
function signtile(x,y,c)
if c==0 then
s='$+$'
else
s='$-$'
end
tex.print("\\node[text width=1.5ex,fill=white,align=center] at ("..x..","..y.."){"..s.."};")
end
function signtiles(x,y,side)
if side==0 then
c1= 0
c2= 1
else
c1= 1
c2= 0
end
signtile(x,y-0.5,c1);
signtile(x+0.5,y,c1);
signtile(x,y+0.5,c2);
signtile(x-0.5,y,c2);
end
-- as : "nenenenen" e:east n:north
-- type: 1: G_n
-- 2: G_n e_n
-- 3: G_n signs
-- 4: signs
-- 5:
-- 6:
-- 7:
function tikzsnake(as,type)
type = type or 1
x=0
y=0
sign=0
asl=0
asl=string.len(as)
if type==1 or type==2 or type==3 then
tex.print("\\node [square={snake square}] at (0,0) (B0) {$G_{1}$};")
else
tex.print("\\node [square={snake square}] at (0,0) (B0) {};")
end
if type==3 then
signtiles(0,0,sign)
end
if type==4 then
if asl>0 then
if 'n' == string.sub(as,1,1) then
signtile(-0.5,0,sign)
sign=1
else
signtile(0,-0.5,sign)
end
else
signtile(0,-0.5,sign)
signtile(0.5,0,sign)
end
end
for i=1,asl do
c=string.sub(as,i,i)
if c=='e' then x=x+1 end
if c=='n' then y=y+1 end
if type==1 or type==2 or type== 3 then
tex.print("\\node [square={snake square}] at ("..x..","..y..") (B"..i..") {$G_{"..(i+1).."}$};")
else
tex.print("\\node [square={snake square}] at ("..x..","..y..") (B"..i..") {};")
end
if type==2 then
if c=='e' then
tex.print("\\node[text width=1.5ex,fill=white,align=center] at ("..(x-0.5)..","..y.."){$e_{"..i.."}$};")
end
if c=='n' then
tex.print("\\node[text width=1.5ex,fill=white,align=center] at ("..x..","..(y-0.5).."){$e_{"..i.."}$};")
end
end
if type==3 then
if sign==1 then sign=0 else sign=1 end
signtiles(x,y,sign)
end
if type==4 then
if i==1 then
if c=='n' then
if sign==1 then sign=0 else sign=1 end
end
else
if c==string.sub(as,i-1,i-1) then
if sign==1 then sign=0 else sign=1 end
end
end
if c=='e' then
signtile(x-0.5,y,sign)
else
signtile(x,y-0.5,sign)
end
if i==asl then
if c=='e' then
signtile(x,y+0.5,sign)
else
signtile(x+0.5,y,sign)
end
end
end
end
end
\end{luacode*}
\fi
%
%
\tikzset{
square/.style={%
draw=none,
circle,
minimum size=1,
append after command={%
\pgfextra \draw[#1] ([shift={(-0.5,0.5)}]\tikzlastnode.center)
--([shift={(0.5,0.5)}]\tikzlastnode.center)
--([shift={(0.5,-0.5)}]\tikzlastnode.center)
--([shift={(-0.5,-0.5)}]\tikzlastnode.center)
--([shift={(-0.5,0.5)}]\tikzlastnode.center)
;\endpgfextra}
},
square/.default=black
}
\pgfkeys{tikz/snake square/.style={black,thick,fill=none}}
\begin{document}
\begin{tikzpicture}[x=1cm,y=1cm]
\node [square={snake square}] at (0,0) (B0) {$G$};
\node [text width=4em,font=\tiny,shift={(0,-0.25)},align=center] at (B0.south) {South};
\node [text width=4em,font=\tiny,shift={(0,0)},align=left] at (B0.west) {West};
\node [text width=4em,font=\tiny,shift={(0,+0.25)},align=center] at (B0.north) {North};
\node [text width=4em,font=\tiny,shift={(0,0)},align=right] at (B0.east) {East};
\end{tikzpicture}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 4
\begin{tikzpicture}[x=1cm,y=1cm]
\tikzset{arc triangle/.style={pos=0.30,left,color=black,font=\small}}
\tikzset{crossing/.style={pos=0.50,color=black,font=\small,fill=white}}
\tikzset{crossing sign/.style={pos=0.70,color=black,font=\tiny,shift={(0,0.2)}}}
\tikzset{b_arc/.style={color=red!60,very thick}}
\tikzset{t_arc/.style={color=blue!60,very thick}}
\draw[b_arc] (0,0) coordinate(S1) --(1,1);
\draw[b_arc] (S1)--(1,-1);
\draw[b_arc] (1,-1)--(8,-1);
\draw[b_arc] (1,1)--(8,1);
\draw[b_arc] (8,1)--(9,0);
\draw[b_arc] (8,-1)--(9,0);
\draw[t_arc] (1,-1)-- node[arc triangle]{$\tau_{11}$} node[crossing]{$p_1$} node[crossing sign]{$-$} (2.5,1);
\draw[t_arc] (2,-1)-- node[arc triangle]{$\tau_2$} node[crossing]{$p_2$} node[crossing sign]{$-$}(2.5,1);
\draw[t_arc] (3,-1)-- node[arc triangle]{$\tau_3$} node[crossing]{$p_3$} node[crossing sign]{$-$} (2.5,1);
\draw[t_arc] (4,-1)-- node[arc triangle]{$\tau_5$} node[crossing]{$p_4$} node[crossing sign]{$-$} (2.5,1);
\draw[t_arc] (4,-1)-- node[arc triangle]{$\tau_6$} node[crossing]{$p_5$} node[crossing sign]{$+$} (6,1);
\draw[t_arc] (5,-1)-- node[arc triangle]{$\tau_7$} node[crossing]{$p_6$} node[crossing sign]{$-$} (6,1);
\draw[t_arc] (6,-1)-- node[arc triangle]{$\tau_9$} node[crossing]{$p_7$} node[crossing sign]{$-$} (6,1);
\draw[t_arc] (7,-1)-- node[arc triangle]{$\tau_4$} node[crossing]{$p_8$} node[crossing sign]{$-$} (6,1);
\draw[t_arc] (8,-1)-- node[arc triangle]{$\tau_{11}$} node[crossing]{$p_9$} node[crossing sign]{$-$} (6,1);
\draw[t_arc] (1,-1)-- node[arc triangle,midway,below]{$\tau_4$} (2,-1);
\draw[t_arc] (2,-1)-- node[arc triangle,midway,below]{$\tau_1$} (3,-1);
\draw[t_arc] (4,-1)-- node[arc triangle,midway,below]{$\tau_8$} (5,-1);
\draw[t_arc] (5,-1)-- node[arc triangle,midway,below]{$\tau_{10}$} (6,-1);
\draw[t_arc] (6,-1)-- node[arc triangle,midway,below]{$\tau_1$} (7,-1);
\draw[t_arc] (7,-1)-- node[arc triangle,midway,below]{$\tau_2$} (8,-1);
\filldraw [gray] (0,0) circle (1pt) coordinate(PS1);
\filldraw [gray] (9,0) circle (1pt) coordinate(PS2);
\node[text width=2ex,fill=none,align=center,font=\small] at ([shift={(-0.2,0)}]PS1.west){$S$};
\node[text width=2ex,fill=none,align=center,font=\small] at ([shift={(0.2,0)}]PS2.east){$S$};
\filldraw [gray] (1,-1) circle (1pt) coordinate(P2);
\filldraw [gray] (2,-1) circle (1pt) coordinate(P3);
\filldraw [gray] (3,-1) circle (1pt) coordinate(P4);
\filldraw [gray] (4,-1) circle (1pt) coordinate(P5);
\filldraw [gray] (5,-1) circle (1pt) coordinate(P6);
\filldraw [gray] (6,-1) circle (1pt) coordinate(P7);
\filldraw [gray] (7,-1) circle (1pt) coordinate(P8);
\filldraw [gray] (8,-1) circle (1pt) coordinate(P9);
\filldraw [gray] (2.5,1) circle (1pt) coordinate(P12);
\filldraw [gray] (6,1) circle (1pt) coordinate(P13);
\draw[color=orange!90,very thick,dashed] (0,0) -- (9,0) node[pos=0.1,above,color=black] {$\gamma$};
\end{tikzpicture}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfkeys{tikz/line bottom/.style={draw=none,append after command={%
\pgfextra \draw[#1] ([shift={(-0.5,-0.5)}]\tikzlastnode.center) --( [shift={(0.5,-0.5)}]\tikzlastnode.center); \endpgfextra}},
tikz/line top/.style={draw=none,append after command={%
\pgfextra \draw[#1] ([shift={(-0.5,0.5)}]\tikzlastnode.center) --( [shift={(0.5,0.5)}]\tikzlastnode.center); \endpgfextra}},
tikz/line left/.style={draw=none,append after command={%
\pgfextra \draw[#1] ([shift={(-0.5,0.5)}]\tikzlastnode.center) --( [shift={(-0.5,-0.5)}]\tikzlastnode.center); \endpgfextra}},
tikz/line right/.style={draw=none,append after command={%
\pgfextra \draw[#1] ([shift={(0.5,0.5)}]\tikzlastnode.center) --( [shift={(0.5,-0.5)}]\tikzlastnode.center); \endpgfextra}},
tikz/borderline/.style={color=red,very thick}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tikzpicture}[x = 1cm,y = 1cm]
\directlua{tikzsnake("eneenne",1)}
\end{tikzpicture}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 15
\begin{tikzpicture}
\directlua{tikzsnake("eneenne",4)}
\end{tikzpicture}
\end{document}