Article View: comp.lang.postscript
Article #8093Bezier trees
From: rob
Date: Thu, 09 Mar 1989 11:17
Date: Thu, 09 Mar 1989 11:17
86 lines
2606 bytes
2606 bytes
I've been reading this group with interest for a few weeks now and I thought
some of you might be interested in a little program to draw trees - I start
with a "curveto" curve and then recurse at a number of points on the curve.
WARNING - don't try this unless your printer is otherwise unoccupied for a
half hour or so!! I've also written a similar program in C to generate "flat"
Postscript output. This allows me to "solve" the curve on the fly and tamper
with each "branch" to my heart's content - I found the prospect of solving
cubic equations in postfix rather daunting! If you've got any suggestions
for improvements (this is my first Postscript program) or you'd like the "C"
version please let me know. You can of course hack this to draw single
trees - the largest sensible recursion depth is 5 (about a half hour). A
depth of 3 takes a several minutes.
Rob Henley
Siemens SDG
8-< -------------------------------------------------------------------------
% ------- Variables & Procedures --------
/depth 0 def
/maxdepth 5 def
/down {/depth depth 1 add def} def
/up {/depth depth 1 sub def} def
/tree
{
gsave
translate % new user space
rotate % rotate
.3 .3 scale % reduce scale
0 0 moveto % move to origin
6 copy % copy 6 top items
curveto % Bezier cubic
stroke % mark the path
% -- recurse at points calculated to be on the curve --
down
depth maxdepth le
{
60 12.5 262.5 tree
-60 28.8 331.2 tree
60 25.9 401.1 tree
-40 -6.4 470.4 tree
90 -78.3 537.3 tree
-40 -132.3 569.3 tree
70 -200 600 tree
-15 -200 600 tree
} if
up
grestore
} def
/season
{
gsave
translate
/maxdepth exch def
200 100 translate
-200 100 300 400 -200 600 0 0 0 tree
grestore
} def
/printbanner
{180 20 moveto (Winter Spring Summer) show} def
% ------- Begin Program --------
newpath
/Times-Italic findfont 30 scalefont setfont
.95 -.05 0 {setgray printbanner -1 .5 translate} for
1 setgray
printbanner
0 setgray
0 0 moveto
2 0 350 season
3 300 350 season
4 0 0 season
5 300 0 season
showpage
Technical Details
Message-ID:
<1189@argon.siesoft>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!sun!pitstop!sundc!seismo!uunet!mcvax!ukc!axion!stc!iclbra!siesoft!robShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!sun!pitstop!sundc!seismo!uunet!mcvax!ukc!axion!stc!iclbra!siesoft!rob From: rob@siesoft (rob) Newsgroups: comp.lang.postscript Subject: Bezier trees Message-ID: <1189@argon.siesoft> Date: 9 Mar 89 11:17:37 GMT Reply-To: rob@.UUCP () Organization: Siemens SDG, woodley, England Lines: 86