bagwill@swe.ncsl.nist.gov (Bob Bagwill) (12/08/90)
%!PS-Adobe-1.0
%%DocumentFonts:
%%Title: RandomTree
%%Creator: Bob Bagwill
%%CreationDate: 6/11/90
%%Pages: 1
%%BoundingBox: (atend)
%%EndComments
%-----------------------------------------------------------------------------
% Draw random binary trees -
% varying reduction, maxdepth, width, branch, length, branching, angle,
% root point and number.
%
% Use with PostScript previewer. Re-execute within same PostScript context
% so that subsequent invocations return different pseudorandom numbers
% (rather than the same first pseudorandom number of the series).
%
% Suggested improvement: save variable values in file so that nice pictures
% can easily be re-created.
%
% Generalized from "PostScript Language Tutorial and Cookbook" example.
% Bob Bagwill, National Institute of Standards and Technology
%------------------------------------------------------------------------------
%-------------Variables----------------
/depth 0 def % current depth
/degrees 5 def % branching gradation
%-------------Procedures---------------
/down {/depth depth 1 add def} def
/up {/depth depth 1 sub def} def
/root { % where to start drawing
2 { 30 random 20 mul % X coord
10 random 10 mul % Y coord
} repeat
} def
/random { % return random
rand srand % uncomment for truly random
rand exch mod 1 add
} def
/mirror { 180 exch sub 2 mul } def % calculate mirror image
/DoLine {
0 branch rlineto
currentpoint stroke translate
0 0 moveto
} def
/RandomTree {
gsave
reduction dup scale
width setlinewidth
down
DoLine
depth maxdepth
le {
angle dup rotate RandomTree % first branch
mirror rotate RandomTree % second branch
} if
up
grestore
} def
%-------------Begin Program---------------
/trees 10 random def % number of trees
trees {
/reduction 5 random 10 div .3 add def
/maxdepth 10 random def
/width 40 random def
/branch 10 random 10 mul 100 add def
/angle 36 random degrees mul def
root moveto
RandomTree
} repeat
stroke
showpage
%%Trailer
%---------------------------end of RandomTree.ps-----------------------------
--
Bob Bagwill NIST
Software Engineering Group/NCSL Technology Bldg, Room B266
bagwill@swe.ncsl.nist.gov Gaithersburg, MD 20899
voice (301)975-3282 fax (301)590-0932