%!PS-Adobe-2.0
%%BoundingBox: 0 400 612 792
%%Pages: 1
%%EndComments
%%Page: 1 1
% cantor.ps
%
% This program generates a picture of Cantor's dust. Just open it in a
% postscript viewer, or print it to a postscript printer.
%
% This is just an illustration of the fact that postscript is in fact a
% programming language and can be used to do things in a programmatic way. Note
% how small this program is.
%
% Copyright (C) 2002 Greg Hamerly (greg_hamerly at baylor dot edu)
%
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
% or see http://www.gnu.org/copyleft/gpl.html
% this is the primary function, which is recursive
% stack arguments:
% i, y1, y0, x1, x0 (top)
% where x/y's define the endpoints of the line
% and i defines the iteration level
/cantordust {
15 dict begin % create a local namespace
0 index /x0 exch def
1 index /x1 exch def
2 index /y0 exch def
3 index /y1 exch def
x0 2 mul x1 add 3 div /xA exch def % first x
y0 2 mul y1 add 3 div /yA exch def % first y
x1 2 mul x0 add 3 div /xB exch def % second x
y1 2 mul y0 add 3 div /yB exch def % second y
4 index % pull up the recursion counter
1 sub % decrement the recursion counter
dup 0 gt % duplicate and compare the counter to 0
{
yA y0 xA x0
cantordust
pop pop pop pop
y1 yB x1 xB
cantordust
pop pop pop pop
}
{
x0 y0 moveto xA yA lineto % draw the line
xB yB moveto x1 y1 lineto
} ifelse % recurse if we haven't bottomed out
pop % remove the recursion counter we put on there
end % pop dictionary off stack
} def
%0.15 setlinewidth
(Helvetica) findfont 20 scalefont setfont
250 750 moveto
(Cantor's dust) show
% this next line determines how many levels of cantor's dust to generate
[ 1 2 3 4 5 6 7 8 9 ]
{
/rl exch def
750 rl 25 mul sub
rl exch
dup 600 20
cantordust
clear
} forall
stroke
showpage