11

I am trying to generate a figure that shows various water particles in a water column where the particles are moving chaotically driven by the cooling and heating of water. So far I have generated an idealized water column with 3 spheres used to represent the water particles.

\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}

enter image description here

However, this seems really unimaginative and I was hoping if anyone had some advice on how o improve the figure from the description given above.

5
  • So you want some random particles at random places? There is a great example about random drawings in the manual. See about the function rnd. When, I get off, I will create one for you. :)
    – nickpapior
    Mar 8, 2013 at 11:48
  • 1
    See also this: tex.stackexchange.com/q/87497/19156 Mar 8, 2013 at 11:52
  • 1
    And also tex.stackexchange.com/q/98754/18674 might be of interest... Mar 8, 2013 at 13:17
  • What do you mean by water particles? Do you mean individually water molecules? The water molecules is what water is. -and they can not in any way be viewed as spheres in a liquid. Mar 10, 2013 at 16:32
  • Well I am trying to draw an annotated diagram of convective mixing in a water body where mixing is driven by the cooling of the water particles (where a they cool and become denser the sink and mix the water column).
    – KatyB
    Mar 10, 2013 at 18:10

1 Answer 1

22

I don't know how much this will get the point, however this is what I imagined the OP had in mind:

enter image description here

Some references for the code:

The idea behind all is to have more particles moving around the hot area, gradually less in the warm area and less in the cold area.

The code:

\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}

First version without shape

enter image description here

The code:

\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}
2
  • By the way, why did you use beamer class rather than standalone class? Mar 10, 2013 at 17:10
  • 1
    Oh.. just because I feel more comfortable with the styles visible on and related (shade on in this case). It's doable also with standalone of course :) Mar 10, 2013 at 17:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .