操作 tikzpicture 和 includegraphics

操作 tikzpicture 和 includegraphics

我正在尝试绘制一个大锅,里面有 2 张图片用于烹饪!我想过使用 来tikz绘制大锅,并通过将图片添加为环境中的节点来包含它们tikzpicture。但是我无法成功地将图片准确地放置在我想要的位置和位置。

我的输出是

在此处输入图片描述

我希望的输出是让图像对称地进入大锅内部,并让大锅内的液体包围它们。

我的 MWE 如下

\PassOptionsToPackage{svgnames}{xcolor}
\documentclass[demo]{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,shadows}
\begin{document}
  \tikzset{
    cauldron filler/.style={draw=black, outer color=black, inner color=black!50, postaction={fill=black, fill opacity=.5}},
    legs/.style={draw=black, fill=black, rounded corners=2pt, isosceles triangle, minimum width=.25},
    cauldron glow/.style={circular glow={fill=#1}},
    rim filler/.style={inner color=black!50, outer color=black},
    liquid/.style={inner color=#1, outer color=#1!75!black},
    pics/cauldron/.style n args=3{
      code={
        \path (-130:1.15*#1 and .8*#1) node [rotate=-130, legs] {};
        \path (-50:1.15*#1 and .8*#1) node [rotate=-50, legs] {};
        \path [cauldron filler] (0,0) circle (1.25*#1 and .9*#1);
        \path [rim filler] (0,0.75*#1) ellipse (.975*#1 and 0.255*#1);
        \path [cauldron glow=#2] (0,.75*#1) circle (.75*#1 and .18*#1);
        \path [liquid=#3] (0,0.75*#1) ellipse (0.825*#1 and 0.1725*#1);
      }
    }
  }
 \centering
 \begin{tikzpicture}
    \path (2,0) pic {cauldron={0.3\columnwidth}{Silver}{Lime}} ++(0,0);
    \node[rotate=45] (image1) at (3,2.5) {\includegraphics[width=0.2\columnwidth]{Mean_Pulse}};
    \node[rotate=-45] (image2) at (0,2.5) {\includegraphics[width=0.2\columnwidth]{Stack_2}};
  \end{tikzpicture}
\end{document}

有什么想法可以让它发挥作用吗?

答案1

我认为clip可以提供帮助。还grid可以帮助定位nodes

\PassOptionsToPackage{svgnames}{xcolor}
\documentclass[]{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,shadows}
\begin{document}
  \tikzset{
    cauldron filler/.style={draw=black, outer color=black, inner color=black!50, postaction={fill=black, fill opacity=.5}},
    legs/.style={draw=black, fill=black, rounded corners=2pt, isosceles triangle, minimum width=.25},
    cauldron glow/.style={circular glow={fill=#1}},
    rim filler/.style={inner color=black!50, outer color=black},
    liquid/.style={inner color=#1, outer color=#1!75!black},
    pics/cauldron/.style n args=3{
      code={
        \path (-130:1.15*#1 and .8*#1) node [rotate=-130, legs] {};
        \path (-50:1.15*#1 and .8*#1) node [rotate=-50, legs] {};
        \path [cauldron filler] (0,0) circle (1.25*#1 and .9*#1);
        \path [rim filler] (0,0.75*#1) ellipse (.975*#1 and 0.255*#1);
        \path [cauldron glow=#2] (0,.75*#1) circle (.75*#1 and .18*#1);
        \path [liquid=#3] (0,0.75*#1) ellipse (0.825*#1 and 0.1725*#1);
      }
    }
  }
 \centering
 \begin{tikzpicture}
    \path (2,0) pic {cauldron={0.3\columnwidth}{Silver}{Lime}} ++(0,0);
    \begin{scope}
    \clip (-2,2.5) rectangle (5,5);
    \node[rotate=60] (image1) at (3.5,2.5) {\includegraphics[width=0.2\columnwidth]{example-image-a}};
    \node[rotate=-45] (image2) at (1,2.5) {\includegraphics[width=0.2\columnwidth]{example-image-b}};
    \end{scope}
%   \draw[red, help lines] (0,0) grid (5,5);
  \end{tikzpicture}
\end{document}

在此处输入图片描述

更新:Alenanno 的ragged border

正如 Alenanno 所建议的,ragged border可以向剪辑矩形添加一个。它会产生boiling效果。decorations.pathmorphing还必须加载库。

\PassOptionsToPackage{svgnames}{xcolor}
\documentclass[]{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,shadows,decorations.pathmorphing}
\begin{document}
  \tikzset{
    cauldron filler/.style={draw=black, outer color=black, inner color=black!50, postaction={fill=black, fill opacity=.5}},
    legs/.style={draw=black, fill=black, rounded corners=2pt, isosceles triangle, minimum width=.25},
    cauldron glow/.style={circular glow={fill=#1}},
    rim filler/.style={inner color=black!50, outer color=black},
    liquid/.style={inner color=#1, outer color=#1!75!black},
    pics/cauldron/.style n args=3{
      code={
        \path (-130:1.15*#1 and .8*#1) node [rotate=-130, legs] {};
        \path (-50:1.15*#1 and .8*#1) node [rotate=-50, legs] {};
        \path [cauldron filler] (0,0) circle (1.25*#1 and .9*#1);
        \path [rim filler] (0,0.75*#1) ellipse (.975*#1 and 0.255*#1);
        \path [cauldron glow=#2] (0,.75*#1) circle (.75*#1 and .18*#1);
        \path [liquid=#3] (0,0.75*#1) ellipse (0.825*#1 and 0.1725*#1);
      }
    },
    ragged border/.style={ decoration={random steps, segment length=1mm, amplitude=0.5mm},decorate,}
  }
 \centering
 \begin{tikzpicture}
    \path (2,0) pic {cauldron={0.3\columnwidth}{Silver}{Lime}} ++(0,0);
    \begin{scope}
    \clip[ragged border] (-2,2.5) rectangle (5,5);
    \node[rotate=60] (image1) at (3.5,2.5) {\includegraphics[width=0.2\columnwidth]{example-image-a}};
    \node[rotate=-45] (image2) at (1,2.5) {\includegraphics[width=0.2\columnwidth]{example-image-b}};
    \end{scope}
%   \draw[red, help lines] (0,0) grid (5,5);
  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容