具有碎玻璃效果的矩阵图像

具有碎玻璃效果的矩阵图像

我有一个矩阵,其主维度是无限的,我想在矩阵图本身中反映这一点。下图不是我想要的,但它说明了要点。我更希望有一个矩阵,其最下面一行看起来就像原本应该在那里的行已经破碎了(想想卡通破碎的玻璃边缘效果)。

在此处输入图片描述

只是想强调一下,我并不想完全复制此图像 - 我只是想要一种破碎边缘效果(比此示例更锯齿状)。有没有简单的方法可以实现这一点?

答案1

这是众多可能性中的一种。请注意,complete sines距离是量化的,这意味着如果你稍微改变一些距离,影响可能会比预期的要大。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix}
% from https://tex.stackexchange.com/a/25689/121799
\usetikzlibrary{decorations}
\pgfdeclaredecoration{complete sines}{initial}
{
    \state{initial}[
        width=+0pt,
        next state=sine,
        persistent precomputation={\pgfmathsetmacro\matchinglength{
            \pgfdecoratedinputsegmentlength / int(\pgfdecoratedinputsegmentlength/\pgfdecorationsegmentlength)}
            \setlength{\pgfdecorationsegmentlength}{\matchinglength pt}
        }] {}
    \state{sine}[width=\pgfdecorationsegmentlength]{
        \pgfpathsine{\pgfpoint{0.25\pgfdecorationsegmentlength}{0.5\pgfdecorationsegmentamplitude}}
        \pgfpathcosine{\pgfpoint{0.25\pgfdecorationsegmentlength}{-0.5\pgfdecorationsegmentamplitude}}
        \pgfpathsine{\pgfpoint{0.25\pgfdecorationsegmentlength}{-0.5\pgfdecorationsegmentamplitude}}
        \pgfpathcosine{\pgfpoint{0.25\pgfdecorationsegmentlength}{0.5\pgfdecorationsegmentamplitude}}
}
    \state{final}{}
}
\begin{document}
\begin{tikzpicture}[decoration={complete sines,amplitude=8pt, segment length=11pt}]
\matrix (m) [fill=blue!20,matrix of nodes,inner sep=0pt,
nodes={draw,minimum width=9mm,minimum height=5mm},
column sep=-\pgflinewidth/2,row sep=-\pgflinewidth/2,]%
{
105 & 102 & 96 & \phantom{123}\\
103 & 99 & 107 & \phantom{123}\\
101 & 98 & 105 & \phantom{123}\\
\phantom{123} & \phantom{123} & \phantom{123} & \phantom{123} \\
};
\fill[white,decorate,overlay] ([xshift=6mm,yshift=10pt]m.north east) coordinate (tl)
 -- ([xshift=-5mm,yshift=10pt]m.north east)
 --  ([xshift=-5mm,yshift=10pt]m.south east) 
 -- ([xshift=-5pt,yshift=10pt]m.south west) 
 -- ++ (0,-18pt) -| cycle;
\end{tikzpicture}
\end{document}

在此处输入图片描述

另一种可能性是将矩阵剪裁成某种(预定义的)形状。我在这里使用的是云,但它可以是任何东西。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix,shapes}
\makeatletter
\tikzset{ % https://tex.stackexchange.com/a/38995/121799
  use path/.code={\pgfsyssoftpath@setcurrentpath{#1}}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{pgfinterruptboundingbox}
\node[cloud,save path=\Cloud,aspect=2,cloud puffs=20,
minimum width=4.5cm,minimum height=2.5cm%,draw
] (cloud){};
\clip[use path=\Cloud];
\end{pgfinterruptboundingbox}
\matrix (m) at ([xshift=3mm,yshift=-3mm]cloud.north west) [anchor=north west,
fill=blue!20,matrix of nodes,inner sep=0pt,
nodes={draw,minimum width=9mm,minimum height=5mm},
column sep=-\pgflinewidth/2,row sep=-\pgflinewidth/2,]%
{
105 & 102 & 96 & \phantom{123}\\
103 & 99 & 107 & \phantom{123}\\
101 & 98 & 105 & \phantom{123}\\
\phantom{123} & \phantom{123} & \phantom{123} & \phantom{123} \\
};
\end{tikzpicture}
\end{document}

在此处输入图片描述

(似乎无法path picture轻易地将矩阵放入其中,否则这里的事情会简化。)

相关内容