Skip to content

Commit

Permalink
add \colorcell function
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuyaoyu committed Jan 16, 2022
1 parent 7f2ac57 commit 0c6344d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,6 @@ TSWLatexianTemp*
# Makeindex log files
*.lpz
*.pdf

# Testing codes
test.*
24 changes: 24 additions & 0 deletions tikz-minesweeper.docs.tex
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,30 @@
\quad
\subfloat[\texttt{\textbackslash tlboard}]{\begin{tikzpicture}\begin{scope}[scale=3]\tlboard{1}{1}\end{scope}\end{tikzpicture}}
\end{figure}
\item[\texttt{\textbackslash colorcell\{颜色\}\{位置\}}] 将[位置]位置的方格染色为[颜色]颜色.
\begin{multicols}{2}
\begin{verbatim}
\begin{tikzpicture}
\board{3}{5}
\row{0}{f{20}123}
\row{1}{A-405}
\row{2}{m-678}
\colorcell{green}{(1,1),(1:2,3:5)}
\end{tikzpicture}
\end{verbatim}
\columnbreak
\begin{figure}[H]
\centering
\begin{tikzpicture}
\board{3}{5}
\row{0}{f{20}123}
\row{1}{A-405}
\row{2}{m-678}
\colorcell{green}{(1,1),(1:2,3:5)}
\end{tikzpicture}
\caption*{方格染色}
\end{figure}
\end{multicols}
\end{itemize}

\end{document}
43 changes: 43 additions & 0 deletions tikz-minesweeper.sty
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[2022/01/07, v0.1.0]
\RequirePackage{tikz}
\RequirePackage{expl3}
\RequirePackage{xstring}

% Color tables
\definecolor{color0}{RGB}{192,192,192}
Expand Down Expand Up @@ -121,6 +122,48 @@
\newcommand{\row}[2]{\element_row:nn {#1}{#2}}
\ExplSyntaxOff

\newcommand{\colorcell}[2]{
\newcounter{i1}
\newcounter{i2}
\newcounter{j1}
\newcounter{j2}
\begin{scope}
\foreach \x in {#2}{
\StrLen{\x}[\len]
\IfBeginWith{\x}{(}{
\StrMid{\x}{2}{\numexpr\len-1}[\y] % remove parenthesis
\StrBefore{\y}{,}[\istr]
\StrBehind{\y}{,}[\jstr]
}{
\StrBefore{\x}{,}[\istr]
\StrBehind{\x}{,}[\jstr]
}

\IfSubStr{\istr}{:}{
\StrBefore{\istr}{:}[\tmp1]
\setcounter{i1}{\tmp1}
\StrBehind{\istr}{:}[\tmp2]
\setcounter{i2}{\tmp2}
}{
\setcounter{i1}{\istr}
\setcounter{i2}{\istr}
}

\IfSubStr{\jstr}{:}{
\StrBefore{\jstr}{:}[\tmp1]
\setcounter{j1}{\tmp1}
\StrBehind{\jstr}{:}[\tmp2]
\setcounter{j2}{\tmp2}
}{
\setcounter{j1}{\jstr}
\setcounter{j2}{\jstr}
}

\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);
}
\end{scope}
}

%%%%%%%%%%%
% BORDERS %
%%%%%%%%%%%
Expand Down

0 comments on commit 0c6344d

Please sign in to comment.