🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.postscript
3 messages
3 total messages Started by Barry G. Adams Thu, 20 Aug 1992 12:49
chaos game: Sierpinski Surprise
#1830
Author: Barry G. Adams
Date: Thu, 20 Aug 1992 12:49
77 lines
2571 bytes
Here is an interesting postscript program which generates the
Sierpinski gasket using the chaos game.

------------------------ CUT HERE --------------------------------
%!
% chaos.ps: The chaos game
% Reference: Fractals For the Classroom, by Peitgen, Jurgens and Saupe
% Author: Barry G. Adams (barry@ramsey.cs.laurentian.ca)

% Procedure for plotting a pixel
1 setlinecap
0.2 setlinewidth
/plotpixel { moveto 0.2 0 rlineto stroke} def

% getting random integer array index 0, 1, or 2
/randindex {rand 3 mod} def

% triangle vertices
/xvertices [100 520 310] def
/yvertices [100 100 380] def

% procedure for computing average of two numbers
/avg { add 2 div } def

% Procedure for drawing triangle outline
/triangle {
   newpath
      xvertices 0 get yvertices 0 get moveto
      xvertices 1 get yvertices 1 get lineto
      xvertices 2 get yvertices 2 get lineto 
   closepath
   stroke
} def

% Play the game:
% (1) Initialize a current point
% (2) randomly generate a triangle vertex number (0, 1, 2),
% (3) calculate the midpoint of the line joining this vertex
%     to the current point, plot the midpoint and make it the
%     new current point.
% (4) go to (2)
/playgame {
   /numpoints exch def % get number of points
   % initialize the current point
   /cpx xvertices 0 get xvertices 1 get avg def
   /cpy yvertices 0 get yvertices 2 get avg def
   triangle
   cpx cpy plotpixel
   numpoints {
      /r randindex def
      /cpx xvertices r get cpx avg def
      /cpy yvertices r get cpy avg def 
      cpx cpy plotpixel
   } repeat
} def

/Times-Roman findfont 24 scalefont setfont
100 710 moveto (The Chaos Game: Sierpinski Surprise) show
/Times-Roman findfont 12 scalefont setfont
/str 30 string def

% Play the game with 1000 points
/numpoints 1000 def
gsave
   0 300 translate
   numpoints playgame
   100 300 moveto numpoints str cvs show ( points) show
grestore

% Play the game with 40000 points
/numpoints 40000 def
gsave
   0 0 translate
   numpoints playgame
   100 300 moveto numpoints str cvs show ( points) show
grestore
showpage
Re: chaos game: Sierpinski Surprise
#1846
Author: Paul Gilmartin
Date: Fri, 21 Aug 1992 05:20
22 lines
1132 bytes
In article <1992Aug20.124923.18308@ramsey.cs.laurentian.ca>
barry@ramsey.cs.laurentian.ca (Barry G. Adams) writes:
 
>Here is an interesting postscript program which generates the
>Sierpinski gasket using the chaos game.
 
[lotsa code deleted]
 
When I try this on the IBM VM PostScript interpreter, I get:
 
    %%[ Error: limitcheck; OffendingCommand: stroke ]%%
 
So I looked at how Don Lancaster drew a dot once, and changed:
 
>/plotpixel { moveto 0.2 0 rlineto stroke} def
 
To:
 
 /plotpixel { moveto closepath     stroke} def
 
And the problem vanished!  But I have no idea why.
It's Fairly Mysterious.  :-)
Re: chaos game: Sierpinski Surprise
#1853
Author: games
Date: Fri, 21 Aug 1992 16:52
14 lines
888 bytes
> In article <1992Aug20.124923.18308@ramsey.cs.laurentian.ca>
> barry@ramsey.cs.laurentian.ca (Barry G. Adams) writes:
>  
>>Here is an interesting postscript program which generates the
>>Sierpinski gasket using the chaos game.
>  
Could someone send this to me, I don't seem to see the original post
anywhere.

		Thanx.

(Or even just repost it?)

		John.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads