使用预定义轮廓绘制网格

使用预定义轮廓绘制网格

我使用以下代码从答案这个帖子这个帖子用预定义的形状填充矩形网格。

是否可以使用除默认的矩形形状之外的预定义轮廓来填充网格;例如如下图所示!

\documentclass[12pt,a4paper]{article}
\usepackage{verbatim}
\usepackage{tikz}
\usepackage{geometry}
\geometry{a4paper, left=10mm, right=10mm, top=8mm, bottom=15mm}
\begin{document}
\pgfmathsetmacro{\lwdth}{.3mm}
\pgfmathsetmacro{\opc}{0.6}
\def\refpnt{%
\fill[black] (0,0) circle [radius=4pt];
}

%begin defining fill colours ==========================
\tikzset{%
filrd/.style={% 
fill=red},
filgr/.style={%
fill=green},
filbl/.style={%
fill=blue},
}
%end defining  fill colours ==========================
%begin defining grid ==========================
\newcommand\sqw{1}
\tikzset{
pics/square/.default={\sqw},
pics/square/.style = {
code = {
\draw[pic actions, draw=none] (0,0) rectangle (#1,#1);
}}}%draw=none is to avoid displaying the little squares outline

\renewcommand\sqw{1.4}
%end defining grid ==========================
%begin defining pentoshapes solution ==========================
\tikzset
{%
%
pics/pent-W/.style={code={\draw[xscale=#1, filrd] (1*\sqw,0*\sqw) |- (0*\sqw,1*\sqw) |- (1*\sqw,3*\sqw) |- (2*\sqw,2*\sqw) |- (3*\sqw,1*\sqw) |- cycle;
\refpnt
}},%
pics/pent-W/.default={1},%
%
pics/pent-Z/.style={code={\draw[xscale=#1, filbl] (1*\sqw,0*\sqw) |- (0*\sqw,2*\sqw) |- (2*\sqw,3*\sqw) |- (3*\sqw,1*\sqw) |- cycle;
\refpnt
}},%
pics/pent-Z/.default={1},%
%
pics/pent-L/.style={code={\draw[xscale=#1, filgr] (0*\sqw,0*\sqw) |- (1*\sqw,4*\sqw) |- (2*\sqw,1*\sqw) |- cycle;
\refpnt
}},%
pics/pent-L/.default={1},%
}%
%end defining pentoshapes solution ==========================

\begin{center}
\begin{tikzpicture}[scale=1, transform shape, fill opacity=\opc, line width=\lwdth]
\draw[step=\sqw] (\sqw,\sqw) grid (15*\sqw, 16*\sqw);
%
\node at (4.5*\sqw,10.5*\sqw) {\huge\bf W};
\pic [rotate=90] at (5*\sqw,7*\sqw) {pent-W};
%
\node at (7.5*\sqw,11.5*\sqw) {\huge\bf Z};
\pic [rotate=0] at (6*\sqw,8*\sqw) {pent-Z};
%
\node at (9.5*\sqw,13.5*\sqw) {\huge\bf L};
\pic [rotate=0] at (10*\sqw,9*\sqw) {pent-L={-1}};
%
\end{tikzpicture}
\end{center}
\end{document}

在此处输入图片描述

在此处输入图片描述

相关内容