带有噪声成分的随机点

带有噪声成分的随机点

我想知道如何用虚线填充指定区域。我想用绿色随机点填充绿色区域,而不是用红色随机点填充红色区域,用蓝色随机点填充白色区域。这是我的代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
%\usepackage{xcolor,pict2e}% to allow any radius

  \tikzset{pics/myarc/.style args={inner #1 and outer #2 with fill #3}{
  code={
    \draw[very thick, #1] (1,0) arc (0:90:1cm);
    \draw[very thick] (0,1) -- (0,2);
    \draw[very thick, #2] (0,2) arc (90:0:2cm);
    \draw[very thick] (2,0) -- (1,0);
    \fill[#3] (1,0) arc (0:90:1cm) -- (0,2) arc (90:0:2cm) -- cycle;
  }
}}
\begin{document}
\begin{tikzpicture}
\draw[very thick,<->] (-6,0) -- (6,0)node[anchor=north west] {$x$};
\pic [draw,very thick, rotate=-45]      {myarc={inner blue and outer blue with fill green!}};
\pic [draw, very thick, rotate=45]      {myarc={inner blue and outer blue with fill white}};
\pic [draw, very thick, rotate=135]      {myarc={inner blue and outer blue with fill red!40}};
\pic [draw, very thick, rotate=225]      {myarc={inner cyan and outer blue with fill white}};
\end{tikzpicture}

\end{document}

在此处输入图片描述

任何帮助都将不胜感激。谢谢

答案1

带有规则的点。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,patterns}
%\usepackage{xcolor,pict2e}% to allow any radius

  \tikzset{pics/myarc/.style args={inner #1 and outer #2 with fill #3}{
  code={
    \draw[very thick, #1] (1,0) arc (0:90:1cm);
    \draw[very thick] (0,1) -- (0,2);
    \draw[very thick, #2] (0,2) arc (90:0:2cm);
    \draw[very thick] (2,0) -- (1,0);
    \fill[pattern=dots,pattern color = #3] (1,0) arc (0:90:1cm) -- (0,2) arc (90:0:2cm) -- cycle;
  }
}}
\begin{document}
\begin{tikzpicture}
\draw[very thick,<->] (-6,0) -- (6,0)node[anchor=north west] {$x$};
\pic [draw,very thick, rotate=-45]      {myarc={inner blue and outer blue with fill green!}};
\pic [draw, very thick, rotate=45]      {myarc={inner blue and outer blue with fill blue}};
\pic [draw, very thick, rotate=135]      {myarc={inner blue and outer blue with fill red!40}};
\pic [draw, very thick, rotate=225]      {myarc={inner cyan and outer blue with fill blue}};
\end{tikzpicture}

\end{document}

在此处输入图片描述

随机化需要做更多工作,这个问题并且它的答案应该引起人们的注意。

以下是使用以下策略的尝试这个答案

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,patterns}
%\usepackage{xcolor,pict2e}% to allow any radius

  \tikzset{pics/myarc/.style args={inner #1 and outer #2 with fill #3}{
  code={
    \draw[very thick, #1] (1,0) arc (0:90:1cm);
    \draw[very thick] (0,1) -- (0,2);
    \draw[very thick, #2] (0,2) arc (90:0:2cm);
    \draw[very thick] (2,0) -- (1,0);
    \clip (1,0) arc (0:90:1cm) -- (0,2) arc (90:0:2cm) -- cycle;
    \foreach \x in {1,...,300}
        {
            \pgfmathrandominteger{\a}{5}{300}
            \pgfmathrandominteger{\b}{5}{300}
            \pgfmathrandominteger{\c}{30}{30}
            \fill[#3] (0.01*\a,0.01*\b) circle (0.001*\c);
        };
  }
}}
\begin{document}
\begin{tikzpicture}
\draw[very thick,<->] (-6,0) -- (6,0)node[anchor=north west] {$x$};
\pic [draw,very thick, rotate=-45]      {myarc={inner blue and outer blue with fill green!}};
\pic [draw, very thick, rotate=45]      {myarc={inner blue and outer blue with fill blue}};
\pic [draw, very thick, rotate=135]      {myarc={inner blue and outer blue with fill red!40}};
\pic [draw, very thick, rotate=225]      {myarc={inner cyan and outer blue with fill blue}};
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容