使用此代码:
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
\newcounter{coreRot}\setcounter{coreRot}{45}
\begin{tikzpicture}[scale=5]
\foreach \x in {0,1,...,7}
\foreach \y in {0,1,...,7}
{
\draw [rotate=\arabic{coreRot},draw,fill] (\x mm,\y mm) rectangle ++(.5mm,.2mm){};
\addtocounter{coreRot}{90};
}
\end{tikzpicture}
\end{document}
我得到这个图像:
但我想要一张这样的图像:
如何在水平和垂直方向的每个步骤之后获得水平行和矩形的旋转?如何在每个步骤之后在 \foreach 循环中旋转矩形?
答案1
你可以从这样的事情开始
\documentclass[11pt]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[cyan] (0,0) grid (7,7);
\foreach \y in {0,...,7}
\foreach \x in {0,...,7}
\node[rotate=45+\x*90+\y*90,rectangle,minimum width=5mm,minimum height=2mm,inner sep=0pt,fill=violet] at (\x,\y) {};
\end{tikzpicture}
\end{document}