装饰(使用随机步骤)填充图案

装饰(使用随机步骤)填充图案
\fill[pattern=north east lines] (A,B) rectangle (C,D);

如何制作图案所形成的条纹具有风格decoration = {random steps, segment length = 0.5mm, amplitude = 0.15pt}

答案1

您可以声明新模式。TikZ手册在第 78 章中对此进行了讨论。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing, patterns}
\begin{document}
\pgfdeclarepatternformonly{mystripes}
{\pgfpointorigin}{\pgfpoint{1cm}{1cm}}
{\pgfpoint{1cm}{1cm}}
{
  \tikz\draw[decoration = {random steps, segment length = 0.5mm, amplitude = 0.15pt}, decorate] (0,0) -- ++(1,1);
}
\begin{tikzpicture}
  \filldraw[pattern=mystripes] (0,0)   rectangle (1.5,2);
\end{tikzpicture}
\end{document}

稍微玩一下,以获得更多的线条,使其参数化,等等。

一个可能的参数可能是两条线之间的距离:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing, patterns}
\begin{document}
\tikzset{mystripes dist/.initial=0.25}
\pgfdeclarepatternformonly[/tikz/mystripes dist]{mystripes}
{\pgfpointorigin}{\pgfpoint{1cm}{1cm}}
{\pgfpoint{1cm}{1cm}}
{
  \foreach \x in {0,\pgfkeysvalueof{/tikz/mystripes dist},...,1}{
    \pgfmathsetmacro{\nx}{1-\x}
    \tikz[overlay]\draw[decoration = {random steps, segment length = 0.5mm, amplitude = 0.15pt}, decorate] (\x, 0) -- ++(\nx,\nx);
    \tikz[overlay]\draw[decoration = {random steps, segment length = 0.5mm, amplitude = 0.15pt}, decorate] (0, \x) -- ++(\nx,\nx);
  }
}
\begin{tikzpicture}
  \filldraw[pattern=mystripes] (0,0)   rectangle (1.5,2);
  \filldraw[pattern=mystripes, xshift=2cm, mystripes dist=0.1] (0,0) rectangle (1.5,2);
\end{tikzpicture}
\end{document}

结果如下:

TikZ 模式

相关内容