Skip to content

Commit 0c6344d

Browse files
committedJan 16, 2022
add \colorcell function
1 parent 7f2ac57 commit 0c6344d

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed
 

Diff for: ‎.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,6 @@ TSWLatexianTemp*
275275
# Makeindex log files
276276
*.lpz
277277
*.pdf
278+
279+
# Testing codes
280+
test.*

Diff for: ‎tikz-minesweeper.docs.tex

+24
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,30 @@
197197
\quad
198198
\subfloat[\texttt{\textbackslash tlboard}]{\begin{tikzpicture}\begin{scope}[scale=3]\tlboard{1}{1}\end{scope}\end{tikzpicture}}
199199
\end{figure}
200+
\item[\texttt{\textbackslash colorcell\{颜色\}\{位置\}}] 将[位置]位置的方格染色为[颜色]颜色.
201+
\begin{multicols}{2}
202+
\begin{verbatim}
203+
\begin{tikzpicture}
204+
\board{3}{5}
205+
\row{0}{f{20}123}
206+
\row{1}{A-405}
207+
\row{2}{m-678}
208+
\colorcell{green}{(1,1),(1:2,3:5)}
209+
\end{tikzpicture}
210+
\end{verbatim}
211+
\columnbreak
212+
\begin{figure}[H]
213+
\centering
214+
\begin{tikzpicture}
215+
\board{3}{5}
216+
\row{0}{f{20}123}
217+
\row{1}{A-405}
218+
\row{2}{m-678}
219+
\colorcell{green}{(1,1),(1:2,3:5)}
220+
\end{tikzpicture}
221+
\caption*{方格染色}
222+
\end{figure}
223+
\end{multicols}
200224
\end{itemize}
201225

202226
\end{document}

Diff for: ‎tikz-minesweeper.sty

+43
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
[2022/01/07, v0.1.0]
33
\RequirePackage{tikz}
44
\RequirePackage{expl3}
5+
\RequirePackage{xstring}
56

67
% Color tables
78
\definecolor{color0}{RGB}{192,192,192}
@@ -121,6 +122,48 @@
121122
\newcommand{\row}[2]{\element_row:nn {#1}{#2}}
122123
\ExplSyntaxOff
123124

125+
\newcommand{\colorcell}[2]{
126+
\newcounter{i1}
127+
\newcounter{i2}
128+
\newcounter{j1}
129+
\newcounter{j2}
130+
\begin{scope}
131+
\foreach \x in {#2}{
132+
\StrLen{\x}[\len]
133+
\IfBeginWith{\x}{(}{
134+
\StrMid{\x}{2}{\numexpr\len-1}[\y] % remove parenthesis
135+
\StrBefore{\y}{,}[\istr]
136+
\StrBehind{\y}{,}[\jstr]
137+
}{
138+
\StrBefore{\x}{,}[\istr]
139+
\StrBehind{\x}{,}[\jstr]
140+
}
141+
142+
\IfSubStr{\istr}{:}{
143+
\StrBefore{\istr}{:}[\tmp1]
144+
\setcounter{i1}{\tmp1}
145+
\StrBehind{\istr}{:}[\tmp2]
146+
\setcounter{i2}{\tmp2}
147+
}{
148+
\setcounter{i1}{\istr}
149+
\setcounter{i2}{\istr}
150+
}
151+
152+
\IfSubStr{\jstr}{:}{
153+
\StrBefore{\jstr}{:}[\tmp1]
154+
\setcounter{j1}{\tmp1}
155+
\StrBehind{\jstr}{:}[\tmp2]
156+
\setcounter{j2}{\tmp2}
157+
}{
158+
\setcounter{j1}{\jstr}
159+
\setcounter{j2}{\jstr}
160+
}
161+
162+
\fill[opacity=0.2,#1] (\numexpr16*\value{j1}-16\relax, \numexpr-16*\value{i1}+16\relax) rectangle (\numexpr16*\value{j2}\relax, \numexpr-16*\value{i2}\relax);
163+
}
164+
\end{scope}
165+
}
166+
124167
%%%%%%%%%%%
125168
% BORDERS %
126169
%%%%%%%%%%%

0 commit comments

Comments
 (0)