答案1
以下是使用几个foreach
循环的方法之一
\documentclass{article}
\usepackage{tikz}
\colorlet{darkBrown}{black!90!brown}
\pagecolor{darkBrown}
\begin{document}
\begin{tikzpicture}[transform canvas={shift={(-7,5)}}]
\foreach \j [evaluate={\p=mod(\j,2)}] in {1,...,30}{
\foreach \i in {1,...,6}{
\foreach \s in {1,...,8}{
\path[fill=darkBrown!70!gray,preaction={draw=darkBrown,line width=5pt}] (4.2*\i-2*\p,-\j) circle (2.25-\s*0.25);
}
}
}
\end{tikzpicture}
\end{document}
答案2
这是一个非常原始的解决方案,它不允许轻松定制,但可以让您了解什么是可能的。与之前的答案有足够的不同,让您看到另一种方法:
\documentclass{article}
\usepackage{tikz}
\newcommand{\mypattern}%
{
\fill[orange]circle(1);
\foreach \i in {0.125,0.25,...,1}
{
\draw[purple,line width=2pt] (0,0) circle(\i);
}
}
\begin{document}
\begin{tikzpicture}
\clip (0,0) rectangle (8,-6);
\foreach \k in {0,1,...,14}
{
\pgfmathtruncatemacro{\xs}{(-1)^\k}
\begin{scope}[yshift=-0.5*\k cm, xshift=0.5*\xs cm]
\foreach \j in {0,1,...,4}
{
\begin{scope}[xshift=2*\j cm]
\mypattern
\end{scope}
}
\end{scope}
}
\end{tikzpicture}
\end{document}
答案3
让我将@SebGlav 的 TikZ 回答翻译为 Asymptote。
// an user-defined pattern
// Run on http://asymptote.ualberta.ca/
// translation from SebGlav
// https://tex.stackexchange.com/a/654632/140722
unitsize(1cm);
size(10cm);
pen penfill=brown;
pen pendraw=lightblue;
picture mypattern(){
picture pic;
fill(pic,unitcircle,penfill);
for(int i=0; i<8; ++i)
draw(pic,circle((0,0),.125i),pendraw+2pt);
return pic;}
for(int k=0; k<16; ++k)
for(int j=0; j<5; ++j){
int xs=(-1)^k;
transform t=shift(.5xs+2j,-.5k);
add(t*mypattern());
}
clip(box((0,0),(8,-5)));
shipout(bbox(5mm,invisible));
更短的代码:
size(10cm);
picture mypattern(){
picture pic;
fill(pic,unitcircle,gray);
for(int i=0; i<8; ++i)
draw(pic,circle((0,0),.125i),yellow+2pt);
return pic;}
for(int k=0; k<16; ++k)
for(int j=0; j<5; ++j)
add(shift(.5(-1)^k+2j,-.5k)*mypattern());
clip(box((0,0),(8,-5)));