# [pstricks] Fill polygon with wavy pattern

Denis Girou Denis.Girou at idris.fr
Tue Feb 25 20:37:19 CET 2003

>>>>> "Martin.Buchmann" == Martin Buchmann <Martin_Buchmann at gmx.net> writes:

Martin.Buchmann> So here's what i did. This is exactely what i wanted to have.

Obviously, this is the only important thing!

Martin.Buchmann>          \pspolygon[linewidth=0pt,fillstyle=solid,fillcolor=liquid]%
Martin.Buchmann> 		(3.0,8.7)(3.0,3.2)(3.225,7.5)(3.45,3.2)(3.675,7.5)(3.9,3.2)%
Martin.Buchmann> 		(4.125,7.5)(4.35,3.2)(4.575,7.5)(4.8,3.2)(4.8,8.7)(3.0,8.7)

Martin.Buchmann>          \pspolygon[...]%
Martin.Buchmann>                  (3.0,1.9)(3.0,3.2)(3.225,7.5)(3.45,3.2)(3.675,7.5)(3.9,3.2)%
Martin.Buchmann>                  (4.125,7.5)(4.35,3.2)(4.575,7.5)(4.8,3.2)(4.8,1.9)(3.0,1.9)

If you have only this precise picture to draw, this is of course enough
and there is no reason to spend time to improve the code if you do not need
more.

Nevertheless, you can easily see that the weakness of this solution is that
you must handle by hand a lot of coordinates. This is of course painful and
not usable if you must reuse such a macro in various contexts.

To have a more generic macro (which of course could still be improved,
parametrizing various things), we must do a little programming, but you can
see that here this is rather simple.

\documentclass{article}

\usepackage{pstcol}
\usepackage{pst-plot}
\usepackage[tiling]{pst-fill}

\definecolor{solidhigh}{rgb}{0.4, 0.4, 0.9}
\definecolor{solidlow}{rgb}{0.8, 0.8, 0.9}
\definecolor{liquid}{rgb}{0.3, 0.3, 0.9}

\makeatletter

\def\Wave{{%
\psset{xunit=0.01pt,yunit=1pt}%
\pspicture(0,-1)(360,1)
\psplot[linewidth=0.25pt]{0}{360}{x sin}
\endpspicture}}

\def\LiquidPattern(#1,#2)#3#4#5{%
% #1 = dim X, #2 = dim Y, #3 = step X, #4 = min Y, #5 = max Y
\pspicture(#1,#2)
\psboxfill{\Wave}%
\psframe[fillstyle=solid,fillcolor=liquid,
\moveto(0,0)
\pst at dimg=#3pt
\divide\pst at dimg\tw@
\pst at dimh=\pst at dimg
\pst at dimtonum{\pst at dimh}{\pst at temph}%
\pst at dimtonum{\pst at dimh}{\pst at tempg}%
\multido{\rXA=\pst at temph+#3,\rXB=#3+#3,\rXC=\pst at tempg+#3}{9999}{%
\lineto(\rXA,#5)
% It could have rounding problems testing \rXB < #1,
% so we test \rXB + #3 < #1 ...
\ifdim\rXC pt<#1pt
\lineto(\rXB,#4)
\else
\multidostop
\fi}
\lineto(#1,0)}
\endpspicture}

\makeatother

\setlength{\parindent}{0cm}

\pagestyle{empty}

\begin{document}

\LiquidPattern(4,3){1}{0}{2.8}
\hfill
\LiquidPattern(4,3){0.4}{0.5}{1.5}

\vspace{1cm}

\LiquidPattern(8,8){1}{1.5}{6}

\vspace{1cm}

\LiquidPattern(12,4){2}{0.5}{3.5}

\end{document}

D.G.