On Saturday, July 21, 2012 12:27:51 AM UTC-5, tlvp wrote:
> On Fri, 20 Jul 2012 20:43:48 -0700 (PDT), luser- -droog wrote:
>
> > One bonus from my search: I think my new L-system
> > code is slicker than anyone else's. :)
> >
> > <</F{F - G + F + G - F}/G{G G}>>begin
> > {F - G - G}7{[exch{dup where{exch get aload pop}if}forall]}repeat
> > cvx<</F{3 0 rlineto}/G 1 index/-{120 rotate}/+{-120 rotate}>>begin
> > 100 100 moveto exec fill showpage
>
> Sure is compact. And terse. As I totally fail to follow the geometric
> motivation of even the tiniest morsel in it, I'd even go so far as to call
> it obscure. And oh! would I appreciate a good commenting on it :-) .
>
> Including also why "L" for what I see as a "Kuratowski gasket"?
>
> Cheers (and thanks for the code), -- tlvp
> --
> Avant de repondre, jeter la poubelle, SVP.
Well, here's a slightly different one with comments.
Wikipedia should do the rest.
%!
%Reference:
%
http://en.wikipedia.org/wiki/L-system#Example_7:_Fractal_plant
%
<< %start constructing a dictionary
%Deterministic Context-Free L-System
%simulated by repeated macro-expansion
%of elements in the array with definitions
%in the currentdict
% proc(ie. array) repeat-count DOL expanded-proc
/DOL { % arr M
{ % arr
[ exch % [ arr
{ % [ ... arr_N perform substitutions on each element
currentdict exch 2 copy known % [ ... dict arr_N bool
{get aload pop}{exch pop}ifelse % [ ... arr_N'
} forall % [ arr_0 arr_1 ... arr_N-1
] % arr' zip up array
dup length = %report size of proc
dup 0 exch { /X eq { 1 add } if } forall = %how many 'X's
dup 0 exch { /F eq { 1 add } if } forall = %how many 'F's
()= %blank line
} repeat % arr'^M array transformed M times
cvx % convert array to proc
}
%transformations (Productions)
/X {F -[[X]+ X]+ F[+ F X]- X}
/F {F F}
>>begin %define DOL and transformations
{X} % seed-proc
6 DOL % expanded-proc
<< % graphical interpretation of expanded proc
([){gsave}
(]){currentpoint 1 0 180 arc stroke grestore}
/X{}
/F{0 3 rlineto currentpoint stroke moveto}
/a 25
/-{a rotate}
/+{a neg rotate}
>>begin %define interpretation
200 200 moveto %establish currentpoint
exec %execute the proc
showpage