RosettaCodeData/Task/Fractal-tree/PostScript/fractal-tree-1.ps

47 lines
1.2 KiB
PostScript

%!PS
%%BoundingBox: 0 0 300 300
%%EndComments
/origstate save def
/ld {load def} bind def
/m /moveto ld /g /setgray ld /t /translate ld
/r /rotate ld /l /lineto ld
/rl /rlineto ld /s /scale ld
%%EndProlog
/PerturbateAngle {} def
/PerturbateLength {} def
% ** To add perturbations, define properly PerturbateAngle and PerturbateLength, e.g.
% /PerturbateAngle {realtime 20 mod realtime 2 mod 1 eq {add} {sub} ifelse} def
% /PerturbateLength {realtime 10 mod 100 div realtime 2 mod 1 eq {add} {sub} ifelse} def
/fractree { % [INITLENGTH, SPLIT, SFACTOR, BRANCHES]
dup 3 get 0 gt
{
0 0 m dup 0 get 0 exch l
gsave
dup 0 get 0 exch t
dup 1 get PerturbateAngle r
dup 2 get dup PerturbateLength s
dup aload pop 1 sub 4 array astore fractree stroke
grestore
gsave
dup 0 get 0 exch t
dup 1 get neg PerturbateAngle r
dup 2 get dup PerturbateLength s
dup aload pop 1 sub 4 array astore fractree stroke
grestore
} if pop
} def
%
/BRANCHES 14 def
/INITLENGTH 50 def
/SPLIT 35 def
/SFACTOR .75 def
%
% BB check
%0 0 m 300 0 rl 0 300 rl -300 0 rl closepath stroke
%
0 g 150 0 t
[INITLENGTH SPLIT SFACTOR BRANCHES] fractree stroke
%
showpage origstate restore
%%EOF