在水柱中绘制水粒子 - tikz

在水柱中绘制水粒子 - tikz

我正在尝试生成一个图形,显示水柱中的各种水粒子,这些粒子在水的冷却和加热的驱动下无序地移动。到目前为止,我已经生成了一个理想化的水柱,其中有 3 个球体用于表示水粒子。

\documentclass{article}
\usepackage[margin = 1in]{geometry}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,calc,shapes,shapes.geometric,patterns}
\begin{document}
\begin{tikzpicture}
\shade[bottom color=cyan!60!black, top color=blue!20!white] (0,0) rectangle (4,5);
\foreach \x in {1,1.2,1.4}
\shade[ball color = cyan!20!white] (\x,3) circle (.1);
\end{tikzpicture}
\end{document}

在此处输入图片描述

但是,这似乎真的缺乏想象力,我希望有人能根据上面的描述对如何改进这个数字提出一些建议。

答案1

我不知道这能说明多少问题,但我可以想象 OP 的想法是这样的:

在此处输入图片描述

代码的一些参考:

其背后的想法是让更多的粒子在热区域移动,在温暖区域移动的粒子逐渐减少,在寒冷区域移动的粒子也逐渐减少。

代码:

\documentclass{beamer}
\usepackage{lmodern,tikz}
\usetikzlibrary{shapes.geometric}

\makeatletter
% original code in
% https://tex.stackexchange.com/questions/88040/how-can-we-draw-christmas-animations-with-tikz#88042

\pgfdeclareradialshading[tikz@ball]{water}{\pgfpoint{-0.15cm}{0.4cm}}{%
  rgb(0cm)=(1,1,1);
  color(0.35cm)=(tikz@ball!35!white); 
  color(0.75cm)=(tikz@ball!80!white); 
  rgb(1cm)=(1,1,1)
}
\tikzoption{water color}{\pgfutil@colorlet{tikz@ball}{#1}\def\tikz@shading{water}\tikz@addmode{\tikz@mode@shadetrue}}

% original code by Jake:
% https://tex.stackexchange.com/questions/85743/tikz-pgf-switching-off-shading#85750
\def\tikz@falsetext{false}
\tikzset{
    shade/.code={
        \edef\tikz@temp{#1}%
        \ifx\tikz@temp\tikz@falsetext%
            \tikz@addmode{\tikz@mode@shadefalse}%
        \else%  
            \tikz@addmode{\tikz@mode@shadetrue}%
        \fi
    }
}
\makeatother

% original code by Daniel:
% https://tex.stackexchange.com/questions/55806/tikzpicture-in-beamer#55849
\tikzset{
    invisible/.style={opacity=0,text opacity=0},
    visible on/.style={alt=#1{}{invisible}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} 
    },
}
% original code in
% https://tex.stackexchange.com/questions/84513/highlighting-in-beamer-using-tikz-nodes#84608
\tikzset{
  background shade/.style={#1},
  background shade/.default={shade=false},
  shade on/.style={alt=#1{}{background shade}},
}


\tikzset{water cold particle/.style={
    circle,
    inner sep=2pt, 
    background shade={shading=water,water color=blue!30!white}   
  },
  water warm particle/.style={
    circle,
    inner sep=2pt, 
    background shade={shading=water,water color=blue!40!cyan!80!black}   
  },
  water hot particle/.style={
    circle,
    inner sep=2pt, 
    background shade={shading=water,water color=cyan!60!black}   
  },  
}
\begin{document}
\begin{frame}{}
\begin{tikzpicture}
\node[draw,cylinder,
  minimum width=4.25cm,
  minimum height=5.65cm,
  shape border rotate=90,
  aspect=1,
  bottom color=cyan!60!black, 
  top color=blue!20!white,
  anchor=after bottom] 
  at (-0.1,-0.1){};

\foreach \hotparticles in {1,...,70}{
  \pgfmathrandom{}
  \pgfmathsetmacro\xpos{4*\pgfmathresult}
  \pgfmathrandom{}
  \pgfmathsetmacro\ypos{2*\pgfmathresult}

  \pgfmathrandom{1,2}
  \let\seqa\pgfmathresult
  \pgfmathrandom{3,5} 
  \let\seqb\pgfmathresult
  \pgfmathrandom{4,7}
  \let\seqc\pgfmathresult
  \pgfmathrandom{7,9}
  \let\seqd\pgfmathresult
  \node[water hot particle,shade on=<{\seqa,\seqb,\seqc,\seqd}>] at (\xpos,\ypos) {};
}
\foreach \warmparticles in {1,...,45}{
  \pgfmathrandom{}
  \pgfmathsetmacro\xpos{4*\pgfmathresult}
  \pgfmathrandom{}
  \pgfmathsetmacro\ypos{2*\pgfmathresult+1.5}
  \pgfmathrandom{1,3}
  \let\seqa\pgfmathresult
  \pgfmathrandom{4,6} 
  \let\seqb\pgfmathresult  
  \pgfmathrandom{7,9} 
  \let\seqc\pgfmathresult 
  \node[water warm particle,shade on=<{\seqa,\seqb,\seqc}>] at (\xpos,\ypos) {};
}

\foreach \coldparticles in {1,...,25}{
  \pgfmathrandom{}
  \pgfmathsetmacro\xpos{4*\pgfmathresult}
  \pgfmathrandom{}
  \pgfmathsetmacro\ypos{2*\pgfmathresult+3}
  \pgfmathrandom{1,5}
  \let\seqa\pgfmathresult
  \pgfmathrandom{4,9} 
  \let\seqb\pgfmathresult  
  \node[water cold particle,shade on=<{\seqa,\seqb}>] at (\xpos,\ypos) {};
}

\end{tikzpicture}
\end{frame}
\end{document}

第一版无形状

在此处输入图片描述

代码:

\documentclass{beamer}
\usepackage{lmodern,tikz}

\makeatletter
% original code in
% https://tex.stackexchange.com/questions/88040/how-can-we-draw-christmas-animations-with-tikz#88042

\pgfdeclareradialshading[tikz@ball]{water}{\pgfpoint{-0.15cm}{0.4cm}}{%
  rgb(0cm)=(1,1,1);
  color(0.35cm)=(tikz@ball!35!white); 
  color(0.75cm)=(tikz@ball!80!white); 
  rgb(1cm)=(1,1,1)
}
\tikzoption{water color}{\pgfutil@colorlet{tikz@ball}{#1}\def\tikz@shading{water}\tikz@addmode{\tikz@mode@shadetrue}}

% original code by Jake:
% https://tex.stackexchange.com/questions/85743/tikz-pgf-switching-off-shading#85750
\def\tikz@falsetext{false}
\tikzset{
    shade/.code={
        \edef\tikz@temp{#1}%
        \ifx\tikz@temp\tikz@falsetext%
            \tikz@addmode{\tikz@mode@shadefalse}%
        \else%  
            \tikz@addmode{\tikz@mode@shadetrue}%
        \fi
    }
}
\makeatother

% original code by Daniel:
% https://tex.stackexchange.com/questions/55806/tikzpicture-in-beamer#55849
\tikzset{
    invisible/.style={opacity=0,text opacity=0},
    visible on/.style={alt=#1{}{invisible}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} 
    },
}
% original code in
% https://tex.stackexchange.com/questions/84513/highlighting-in-beamer-using-tikz-nodes#84608
\tikzset{
  background shade/.style={#1},
  background shade/.default={shade=false},
  shade on/.style={alt=#1{}{background shade}},
}


\tikzset{water cold particle/.style={
    circle,
    inner sep=2pt, 
    background shade={shading=water,water color=blue!30!white}   
  },
  water warm particle/.style={
    circle,
    inner sep=2pt, 
    background shade={shading=water,water color=blue!40!cyan!80!black}   
  },
  water hot particle/.style={
    circle,
    inner sep=2pt, 
    background shade={shading=water,water color=cyan!60!black}   
  },  
}
\begin{document}
\begin{frame}{}
\begin{tikzpicture}
\shade[bottom color=cyan!60!black, top color=blue!20!white] (-0.1,-0.1) rectangle (4.1,5.1);

\foreach \hotparticles in {1,...,70}{
  \pgfmathrandom{}
  \pgfmathsetmacro\xpos{4*\pgfmathresult}
  \pgfmathrandom{}
  \pgfmathsetmacro\ypos{2*\pgfmathresult}

  \pgfmathrandom{1,2}
  \let\seqa\pgfmathresult
  \pgfmathrandom{3,5} 
  \let\seqb\pgfmathresult
  \pgfmathrandom{4,7}
  \let\seqc\pgfmathresult
  \pgfmathrandom{7,9}
  \let\seqd\pgfmathresult
  \node[water hot particle,shade on=<{\seqa,\seqb,\seqc,\seqd}>] at (\xpos,\ypos) {};
}
\foreach \warmparticles in {1,...,45}{
  \pgfmathrandom{}
  \pgfmathsetmacro\xpos{4*\pgfmathresult}
  \pgfmathrandom{}
  \pgfmathsetmacro\ypos{2*\pgfmathresult+1.5}
  \pgfmathrandom{1,3}
  \let\seqa\pgfmathresult
  \pgfmathrandom{4,6} 
  \let\seqb\pgfmathresult  
  \pgfmathrandom{7,9} 
  \let\seqc\pgfmathresult 
  \node[water warm particle,shade on=<{\seqa,\seqb,\seqc}>] at (\xpos,\ypos) {};
}

\foreach \coldparticles in {1,...,25}{
  \pgfmathrandom{}
  \pgfmathsetmacro\xpos{4*\pgfmathresult}
  \pgfmathrandom{}
  \pgfmathsetmacro\ypos{2*\pgfmathresult+3}
  \pgfmathrandom{1,5}
  \let\seqa\pgfmathresult
  \pgfmathrandom{4,9} 
  \let\seqb\pgfmathresult  
  \node[water cold particle,shade on=<{\seqa,\seqb}>] at (\xpos,\ypos) {};
}
\end{tikzpicture}
\end{frame}
\end{document}

相关内容