% TeX programs by Anthony Phan.
% file: sierpinski.tex (just an example)
% last modification: December 9, 2000.
% Gratefully dedicated to Elvire Scheibling.

%
% THE MACRO
%
% (Notice that the use of \loop...\repeat would have
% saved a few bytes, but wouldn't have been clearer.)
%

\def\sierpinski#1{{%
	\def\next##1size=##2 ##3\end{\dimen255=##2\relax}%
	\next#1 size=1in \end
	\def\next##1depth=##2 ##3\end{\count255=##2\relax}%
	\next#1 depth=3 \end
	\vbox to \dimen255{\hsize=\dimen255
		\baselineskip=-1000pt
		\lineskip=0pt
		\lineskiplimit=16383pt
		\parskip=0pt
		\count254=0
		\count253=1
		\def\recurse{%
			\ifnum\count254<\count255
				\advance\count254 by 1
				\multiply\count253 by 3
				\recurse
				\setbox0\vbox{\hbox{\copy0\copy0\copy0}%
					\hbox{\copy0\hskip\wd0\copy0}%
					\hbox{\copy0\copy0\copy0}}%
			\else
				\divide\dimen255 by \count253
				\setbox0\hbox{%
					\vrule width\dimen255
					height\dimen255 depth0pt}%
			\fi}
		\vss
		\recurse
		\hbox{\hss\box0\hss}
		\vss}}}

%
% TEST
%

bla bla bla bla bla bla bla bla bla bla bla bla bla bla  
bla bla bla bla bla bla bla bla bla bla bla bla bla bla  
bla bla bla bla bla bla bla bla bla bla bla bla bla bla  
bla bla bla bla bla bla bla bla bla bla bla bla bla bla  
bla bla bla bla bla bla bla bla bla bla bla bla bla bla  
bla bla bla bla bla bla bla bla bla bla bla bla bla bla  
bla bla bla bla bla bla bla bla bla bla bla bla bla bla  
bla bla bla bla bla bla bla bla bla bla bla bla bla bla  
$$
\sierpinski{size=2truecm depth=0}
\qquad
\sierpinski{size=2truecm depth=1}
\qquad
\sierpinski{size=2truecm depth=2}
\qquad
\sierpinski{size=2truecm depth=3}
\qquad
\sierpinski{size=2truecm depth=4}
$$
bla bla bla bla bla bla bla bla bla bla bla bla bla bla  
bla bla bla bla bla bla bla bla bla bla bla bla bla bla  
bla bla bla bla bla bla bla bla bla bla bla bla bla bla  
bla bla bla bla bla bla bla bla bla bla bla bla bla bla  
bla bla bla bla bla bla bla bla bla bla bla bla bla bla  
bla bla bla bla bla bla bla bla bla bla bla bla bla bla  
bla bla bla bla bla bla bla bla bla bla bla bla bla bla  
bla bla bla bla bla bla bla bla bla bla bla bla bla bla  
bla bla bla bla bla bla bla bla bla bla bla bla bla bla  
\bigbreak
\hfill Happy \TeX ing!
\par\hfill Anthony Phan.

\bye

