%% BEGIN pst-electrolysis.tex
%%
%% plotting electrolysis example images
%%
%% COPYRIGHT 2026 Manuel Luque
%%                Herbert Voss, hvoss@tug.org.
%%
%% This program can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License Distributed from CTAN
%% archives in directory macros/latex/base/lppl.txt.
%%
%%
\csname PSTElectrolysisLoaded\endcsname
\let\PSTElectrolysisLoaded\endinput

\ifx\PSTricksLoaded\endinput\else   \input pstricks.tex\fi
\ifx\MultidoLoaded\endinput \else   \input multido.tex \fi
\ifx\GradientLoaded\endinput\else   \input pst-grad.tex\fi
\ifx\PSTXKeyLoaded\endinput \else   \input pst-xkey \fi
%
\def\fileversion{0.01}
\def\filedate{2026/06/10}
\message{ v\fileversion, \filedate}
%
\edef\TheAtCode{\the\catcode`\@}
\catcode`\@=11
\pst@addfams{pst-electrolysis}
%
\input random
\definecolor{Orange}{rgb}{1,0.65,0}
\newdimen{\@BubbleX}
\newdimen{\@BubbleY}
\newdimen{\bubbleHeight}
\bubbleHeight=2pt %Maximum height reached by the bubbles; the points are then converted into centimeters.
\def\pstBubbles#1{{% #1 = 
	\multido{\iBubble=1+1}{#1}{%
		\setrandim{\@BubbleX}{-0.15pt}{0.15pt}
		\setrandim{\@BubbleY}{0pt}{\bubbleHeight}
		\pst@dimh=\@BubbleY
		\ifdim\@BubbleY>1.25pt \pst@dimh=1pt \fi
		\psdot[dotscale=\pointless\pst@dimh,dotstyle=o](! \pointless\@BubbleX\space
		\pointless\@BubbleY)}}}
\psset{dimen=middle}
% the U-tube with a diameter of 1 cm
% de bubbleHeight 5 cm
\def\psTubeU{%
  \pscustom[linestyle=none]{%
	\psline(-2,3)(-2,0)
	\psarc(0,0){2}{180}{0}
	\psline(2,0)(2,3)(1,3)(1,0)
	\psarcn(0,0){1}{0}{180}
	\psline(-1,0)(-1,3)(-2,3)}}
\def\psContourTubeU{%
  \pscustom[linewidth=2\pslinewidth]{%
	\psline(-2,3)(-2,0)
	\psarc(0,0){2}{180}{0}
	\psline(2,0)(2,3)}
  \pscustom[linewidth=2\pslinewidth]{%
	\psline(1,3)(1,0)
	\psarcn(0,0){1}{0}{180}
	\psline(-1,0)(-1,3)}}
%%%%%%%%%%%%%%%%%
\def\psElectrode{%
  \psframe*[linecolor=black](-0.1,0)(0.1,4.5)
  \psframe*[linecolor=Orange](-0.15,4.2)(0.15,4.5)}
\def\psGlassware{%
% inverted test tube
  {\pscustom[linewidth=2\pslinewidth]{%
  	 \psline(-1.45,3.6)(-1.45,6.35)
 	 \psarcn(-1.2,6.35){0.25}{180}{0}
 	 \psline(-0.95,6.35)(-0.95,3.6)}
   \psContourTubeU}
  % delivery tube
  \psline[doubleline=true,doublesep=1mm](-1.2,2)(-1.2,4.5)
  % bouchon
  \pspolygon[fillstyle=solid,fillcolor=gray!50,linewidth=0.025](-2.1,3.5)(-1.9,2.5)(-1.1,2.5)(-0.9,3.5)%
}
%
\def\psElectrolysisA{\@ifnextchar[
    {\psElectrolysisA@i}%
    {\psElectrolysisA@i[]}}
\def\psElectrolysisA@i[#1]{\@ifnextchar[%
    {\psElectrolysisA@ii[#1]}%
    {\psElectrolysisA@ii[#1][]}}
\def\psElectrolysisA@ii[#1][#2]{\@ifnextchar(%
    {\psElectrolysisA@iii[#1][#2]}%
    {\psElectrolysisA@iii[#1][#2](-3,-2)(3,7)}}

\def\psElectrolysisA@iii[#1][#2](#3)(#4){{%
\begin{pspicture}[#1](#3)(#4)
\begin{psclip}{\psTubeU}
	% liquide
	\psframe*[linecolor=gray!20](-3,-2)(3,1.5)
\end{psclip}
\rput(-1.75,0){\psElectrode}
\psGlassware
\psline(-1.7,4.5)(-3,4.5)
\psline(1.5,4.5)(3,4.5)
\rput(-3,4.5){\pscirclebox[fillstyle=solid]{$-$}}
\rput(3,4.5){\pscirclebox[fillstyle=solid]{$+$}}
\psframe[linestyle=none,fillstyle=solid,
   fillcolor=blue!50!magenta!50](1.025,0)(1.975,1.5)
\rput(1.5,0){\psElectrode}
\psline[linewidth=3\pslinewidth,linecolor=red]{->}(2.6,4.5)(2,4.5)
\uput[u](2.4,4.5){\red$I$}
#2
%\psline{->}(-3.1,0.75)(-1.25,0.75)
%\uput[l](-3,0.75){phenolphthalein}
%\psline{->}(3.1,0.75)(2,0.75)
%\uput[r](3,0.75){indigo}
%\psline{->}(0,-2.5)(0,-1.5)
%\uput[d](0,-2.5){solution for $\mathrm{Na^++Cl^-}$}
\end{pspicture}}}

\def\psElectrolysisB{\@ifnextchar[
    {\psElectrolysisB@i}%
    {\psElectrolysisB@i[]}}
\def\psElectrolysisB@i[#1]{\@ifnextchar[%
    {\psElectrolysisB@ii[#1]}%
    {\psElectrolysisB@ii[#1][]}}
\def\psElectrolysisB@ii[#1][#2]{\@ifnextchar(%
    {\psElectrolysisB@iii[#1][#2]}%
    {\psElectrolysisB@iii[#1][#2](-3,-2)(3,7)}}

\def\psElectrolysisB@iii[#1][#2](#3)(#4){{%
%  \psset{#1}%
  \begin{pspicture}[#1](#3)(#4)
	\begin{psclip}{\psTubeU}
		% liquide
		\psframe*[linecolor=gray!20](-3,-2)(3,1.5)
		% release of chlorine gas in the tube
		\psframe[linestyle=none,fillstyle=gradient,gradbegin=green!20,
		         gradend=white,gradmidpoint=0](0,1.5)(3,3)
	\end{psclip}
	\rput(-1.75,0){\psElectrode}
	\rput(1.5,0){\psElectrode}
	\psGlassware
	\psline(-1.7,4.5)(-3,4.5) \psline(1.5,4.5)(3,4.5)
	\rput(-3,4.5){\pscirclebox[fillstyle=solid]{$-$}}
	\rput(3,4.5){\pscirclebox[fillstyle=solid]{$+$}}
	\psframe[linestyle=none,fillstyle=solid,fillcolor=blue!50!magenta!50](1.025,0)(1.975,1.5)
	\pscustom[linecolor=gray!20]{\pscurve(1.3,1.5)(1.2,1)(1.3,-0.2)(1.4,-0.4)(1.7,0)(1.75,1)(1.7,1.5)\fill[fillstyle=solid,fillcolor=gray!20]}
	\pscustom[linecolor=magenta]{\pscurve(-1.9,1.5)(-1.9,1)(-1.8,-0.2)(-1.4,0)(-1.5,1)(-1.5,1.5)\fill[fillstyle=solid,fillcolor=magenta]}%
	\psframe*[linecolor=black](-1.85,0)(-1.65,1.5)
	\psframe*[linecolor=black](1.4,0)(1.6,1.5)
	\rput(-1.75,0){\bubbleHeight=1.5pt\pstBubbles{25}}
	\rput(1.5,0){\psset{fillstyle=solid,fillcolor=green!20}\bubbleHeight=1.5pt\pstBubbles{25}}
	\psline{->}(-1.2,4.6)(-1.2,5.5)\uput[u](-1.2,5.5){\small$\mathrm{H_2}$}
	\psline[linewidth=3\pslinewidth,linecolor=red]{->}(2.6,4.5)(2,4.5)
	\uput[u](2.4,4.5){\red$I$}
	#2
%	\psline{->}(-3.1,0.75)(-2,0.75)
%	\uput[l](-3,0.75){\shortstack{turn of the\\ phenolphthalein}}
%	\psline{->}(3.1,0.75)(2,0.75)
%	\uput[r](3,0.75){\shortstack{discoloration of\\indigo}}
%	\psline{->}(3,2)(1.6,1.25)
%	\uput[r](3,2){release of $\mathrm{Cl_2}$}
%	\psline{->}(-3,2)(-1.8,1.25)
%	\uput[l](-3,2){release of $\mathrm{H_2}$}
\end{pspicture}}}
%
\def\psElectrolysisC{\@ifnextchar[
    {\psElectrolysisC@i}%
    {\psElectrolysisC@i[]}}
\def\psElectrolysisC@i[#1]{\@ifnextchar[%
    {\psElectrolysisC@ii[#1]}%
    {\psElectrolysisC@ii[#1][]}}
\def\psElectrolysisC@ii[#1][#2]{\@ifnextchar(%
    {\psElectrolysisC@iii[#1][#2]}%
    {\psElectrolysisC@iii[#1][#2](-3,-2)(3,7)}}

\def\psElectrolysisC@iii[#1][#2](#3)(#4){{%
\begin{pspicture}[#1](#3)(#4)
\begin{psclip}{\psTubeU}
% liquide
\psframe*[linecolor=cyan!20](-3,-2)(3,1.5)
\end{psclip}
\psContourTubeU
\rput(-1.5,0){\psElectrode}
\rput(1.5,0){\psElectrode}
\psline[linewidth=3\pslinewidth](-0.1,6.3)(-0.1,6.7)
\psline(0.1,6)(0.1,7)
\uput[45](0.1,6.5){$+$}
\uput[135](-0.1,6.5){$-$}
\psline(-1.5,4.5)(-3,4.5)(-3,6.5)(-0.1,6.5)
\psline(1.5,4.5)(3,4.5)(3,6.5)%(0.1,6.5)
\psline(0.1,6.5)(1,6.5)
\psline(2,6.5)(3,6.5)
\psline[linewidth=2\pslinewidth](1,6.5)(2.1,6.7)
\psdot(2,6.5)
\pscircle[fillstyle=solid](1,6.5){0.1}
\pscircle[fillstyle=solid](-3,5.5){0.5}
\rput(-3,5.5){mA}
\psline{*-*}(-3,4.75)(3,4.75)
\pscircle[fillstyle=solid](0,4.75){0.5}
\rput(0,4.75){V}
\uput[135](-0.5,4.75){\footnotesize \textsc{com}}
\uput[135](-3,6){\footnotesize \textsc{com}}
%\psline{<->}(-1.4,2)(1.4,2)
%\psline{->}(-0.75,2)(-1.4,2)
%\rput*(0,2){\shortstack{graphite\\ electrodes}}
%\psline{-*}(2,-1.5)(0,-1.5)
%\uput[0](2,-1.5){\small \shortstack{copper\\ bromide\\ solution}}
#2
\end{pspicture}}}

\def\psElectrolysisD{\@ifnextchar[
    {\psElectrolysisD@i}%
    {\psElectrolysisD@i[]}}
\def\psElectrolysisD@i[#1]{\@ifnextchar[%
    {\psElectrolysisD@ii[#1]}%
    {\psElectrolysisD@ii[#1][]}}
\def\psElectrolysisD@ii[#1][#2]{\@ifnextchar(%
    {\psElectrolysisD@iii[#1][#2]}%
    {\psElectrolysisD@iii[#1][#2](-3,-2)(3,7)}}

\def\psElectrolysisD@iii[#1][#2](#3)(#4){{%
  \begin{pspicture}[#1](#3)(#4)
  \begin{psclip}{\psTubeU}
    % liquide
    \psframe*[linecolor=cyan!20](-3,-2)(3,1.5)
    \psframe*[linecolor=Orange](0,0.5)(3,1.5)
    \psframe[linestyle=none,fillstyle=gradient,gradbegin=Orange,gradend=cyan!20,gradmidpoint=1](0,-0.2)(3,0.5)
  \end{psclip}
  \psContourTubeU
  \rput(-1.5,0){\psElectrode}  \rput(1.5,0){\psElectrode}
  \psline[linewidth=3\pslinewidth](-0.1,6.3)(-0.1,6.7)
  \psline(0.1,6)(0.1,7)
  \uput[45](0.1,6.5){$+$}
  \uput[135](-0.1,6.5){$-$}
  \psline(-1.5,4.5)(-3,4.5)(-3,6.5)(-0.1,6.5)
  \psline(1.5,4.5)(3,4.5)(3,6.5)%(0.1,6.5)
  \psline(0.1,6.5)(1,6.5)
  \psline(2,6.5)(3,6.5)
  \psline[linewidth=2\pslinewidth](1,6.5)(2.1,6.5)
  \psdot(2,6.5)
  \pscircle[fillstyle=solid](1,6.5){0.1}
  \pscircle[fillstyle=solid](-3,5.5){0.5}
  \rput(-3,5.5){mA}
  \psline{*-*}(-3,4.75)(3,4.75)
  \pscircle[fillstyle=solid](0,4.75){0.5}
  \rput(0,4.75){V}
  \uput[135](-0.5,4.75){\footnotesize \textsc{com}}
  \uput[135](-3,6){\footnotesize \textsc{com}}
  %\psline{->}(2.5,0.75)(1.7,0.75)
%\uput[0](2.5,0.75){\shortstack{formation of\\ $\mathrm{Br_2}$ (orange)}}
\rput(-1.5,0){\psframe*[linecolor=red](-0.1,0)(0.1,1.5)}
%\psline{->}(-2.5,0.75)(-1.6,0.75)
%\uput[l](-2.3,0.75){\shortstack{dépôt \\de cuivre}}
#2
\end{pspicture}}}

\catcode`\@=\TheAtCode\relax

\endinput
%%
%% END pst-electrolysis.tex
