在 Tikz 中生成彩色花式 Delaunay 图案

在 Tikz 中生成彩色花式 Delaunay 图案

最近在互联网世界里出现了这种非常奇特的彩色图案:

相似Delaunay模式

我在想是否有可能用 TikZ 生成类似的东西。我在这里看到了第一个例子使用 Tikz 绘制非结构化网格

\documentclass[tikz,border=5]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \i [evaluate={\ii=int(\i-1);}] in {0,...,7}{
  \foreach \j [evaluate={\jj=int(\j-1);}] in {0,...,7}{
    \coordinate [shift={(\j,\i)}] (n-\i-\j) at (rand*180:1/4+rnd/8);
\ifnum\i>0
  \draw [help lines] (n-\i-\j) -- (n-\ii-\j);
\fi
\ifnum\j>0
  \draw [help lines] (n-\i-\j) -- (n-\i-\jj);
  \ifnum\i>0
    \pgfmathparse{int(rnd>.5)}
    \ifnum\pgfmathresult=0
      \draw [help lines] (n-\i-\j) -- (n-\ii-\jj);
    \else%
      \draw [help lines] (n-\ii-\j) -- (n-\i-\jj);
    \fi%
  \fi
\fi
}}
\end{tikzpicture}
\end{document}

这就产生了以下模式:

Delaunay 镶嵌黑白]

这里最大的问题是添加一些带有浅色阴影的随机颜色。TikZ 中是否有某种方法可以指定节点定义的区域内的渐变?

答案1

如果你把路径封闭了,你就可以给它遮荫。

这是基于Mark Wibrow 的代码,如问题中引用的那样。

% answer to https://tex.stackexchange.com/questions/314918/generate-coloured-fancy-delaunay-patterns-in-tikz, modifying code by Mark Wibrow at https://tex.stackexchange.com/a/260652/
\documentclass[tikz,border=10pt,multi,rgb]{standalone}
% xcolor manual: 34
\definecolorseries{colours}{hsb}{grad}[hsb]{.575,1,1}{.987,-.234,0}
\resetcolorseries[12]{colours}
\tikzset{%
  set my colour/.code={%
    \colorlet{mycolour}{colours!!+},
  },
  my colour/.style={%
    set my colour,
    bottom color=mycolour,
    top color=mycolour!50,
    fill opacity=.5,
  },
}
\begin{document}
\begin{tikzpicture}
  \foreach \i [evaluate={\ii=int(\i-1)}, remember=\i as \ilast] in {0,...,7}{
    \foreach \j [evaluate={\jj=int(\j-1)}, remember=\j as \jlast] in {0,...,7}{
      \coordinate [shift={(\j,\i)}] (n-\i-\j) at (rand*180:1/4+rnd/8);
      \ifnum\i>0
        \path [my colour] (n-\i-\j) -- (n-\ii-\j) -- (n-\ilast-\j) -- cycle;
      \fi
      \ifnum\j>0
        \path [my colour] (n-\i-\j) -- (n-\i-\jj) -- (n-\i-\jlast) -- cycle;
        \path [my colour] (n-\i-\jlast) -- (n-\i-\jj) -- (n-\i-\j) -- cycle;
        \ifnum\i>0
           \path [my colour] (n-\i-\j) -- (n-\i-\jj) -- (n-\ii-\j) -- cycle;
           \path [my colour] (n-\ilast-\j) -- (n-\ilast-\jj) -- (n-\i-\j) -- cycle;
          \pgfmathparse{int(rnd>.5)}
          \ifnum\pgfmathresult=0
            \path [my colour] (n-\ilast-\jlast) -- (n-\ilast-\jj) -- (n-\ii-\jj) -- cycle;
            \path [my colour] (n-\ilast-\j) -- (n-\ilast-\jj) -- (n-\ii-\jj) -- cycle;
            \path [my colour] (n-\i-\jlast) -- (n-\i-\jj) -- (n-\ii-\jj) -- cycle;
            \path [my colour] (n-\i-\j) -- (n-\i-\jj) -- (n-\ii-\jj) -- cycle;
            \path [my colour] (n-\ii-\j) -- (n-\i-\jj) -- (n-\i-\j) -- cycle;
          \else
            \path [my colour] (n-\ii-\j) -- (n-\i-\jj) -- (n-\i-\j) -- cycle;
            \path [my colour] (n-\i-\j) -- (n-\i-\jj) -- (n-\ii-\jj) -- cycle;
            \path [my colour] (n-\i-\jlast) -- (n-\i-\jj) -- (n-\ii-\jj) -- cycle;
            \path [my colour] (n-\ilast-\j) -- (n-\ilast-\jj) -- (n-\ii-\jj) -- cycle;
            \path [my colour] (n-\ilast-\jlast) -- (n-\ilast-\jj) -- (n-\ii-\jj) -- cycle;
          \fi
        \fi
      \fi
    }
  }
\end{tikzpicture}
\end{document}

阴影

相关内容