3

I create a pattern and want to change the lines' density when I invoke this pattern. What I have got for now:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}

\newdimen\density
\tikzset{
    density/.code={\density=#1},
    density=3pt
}

\makeatletter
\pgfdeclarepatternformonly[\density]{resizable north east lines}
{\pgfqpoint{-1pt}{-1pt}}
{\pgfqpoint{\density}{\density}}
{\pgfqpoint{\density}{\density}}
{
    \pgfsetcolor{\tikz@pattern@color}
    \pgfsetlinewidth{0.4pt}
    \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
    \pgfpathlineto{\pgfqpoint{\density + 0.1pt}{\density + 0.1pt}}
    \pgfusepath{stroke}
}
\makeatother

\begin{document}
\begin{tikzpicture}

    \node [minimum size = 10 cm, draw = red, line width = 2pt] at (0,0) {};
    \draw [density=10pt, pattern=resizable north east lines, pattern color = red] (0,0) circle[radius = 5cm];

\end{tikzpicture}
\end{document}

How do I define a variable with space in order to invoke it using the following style? (see the pattern density)

\draw [pattern density=10pt, pattern=resizable north east lines, pattern color = red] (0,0) circle[radius = 5cm];
aban
  • 747
  • 7
  • 13

1 Answers1

1

Something like this?

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}

\makeatletter
\newdimen\pattern@density
\tikzset{/tikz/.cd,
    pattern density/.store in=\density,
    pattern density=3pt
}

\pgfdeclarepatternformonly[\density]{resizable north east lines}
{\pgfqpoint{-1pt}{-1pt}}
{\pgfqpoint{\density}{\density}}
{\pgfqpoint{\density}{\density}}
{
    \pgfsetcolor{\tikz@pattern@color}
    \pgfsetlinewidth{0.4pt}
    \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
    \pgfpathlineto{\pgfqpoint{\density + 0.1pt}{\density + 0.1pt}}
    \pgfusepath{stroke}
}
\makeatother

\begin{document}
\begin{tikzpicture}

    \node [minimum size = 10 cm, draw = red, line width = 2pt] at (0,0) {};
    \draw [pattern density=9pt, pattern=resizable north east lines, pattern color = red] (0,0) circle[radius = 5cm];

\end{tikzpicture}
\end{document}