48 lines
1.7 KiB
Text
48 lines
1.7 KiB
Text
1) defining the function tree:
|
|
|
|
{def tree
|
|
{lambda {:e // last branch length
|
|
:s // trunks length
|
|
:k // ratio between two following branches
|
|
:a // rotate left
|
|
:b} // rotate right
|
|
{if {< :s :e}
|
|
then
|
|
else M:s T:a
|
|
{tree :e {* :k :s} :k :a :b}
|
|
T-{+ :a :b}
|
|
{tree :e {* :k :s} :k :a :b}
|
|
T:b M-:s }}}
|
|
|
|
2) Calling this function generates a sequence of commands mooving a pen:
|
|
• Tθ rotates the drawing direction "θ" degrees from the previous one
|
|
• and Md draws a segment "d" pixels in this direction.
|
|
|
|
{def T {tree 1 190 {/ 2 3} 15 45}}
|
|
|
|
and produces 40995 words beginning with:
|
|
|
|
M190 T15 M126.66666666666666 T15 M84.44444444444443 T15 M56.29629629629628 T15 M37.53086419753085 T15 M25.020576131687235 T15
|
|
M16.680384087791488 T15 M11.120256058527659 T15 M7.413504039018439 T15 M4.942336026012292 T15 M3.2948906840081946 ...
|
|
|
|
3) These words are sent to a the turtle lambdatalk primitive
|
|
which is a graphic device translating the sequence of Md and Tθ
|
|
into a sequence of SVG points x0 y0 x1 y1 ... xn yn
|
|
which will feed the points attribute of a polyline SVG element:
|
|
|
|
{svg {@ width="580px" height="580px" style="box-shadow:0 0 8px #000;"}
|
|
{polyline
|
|
{@ points="{turtle 230 570 180 {T}}"
|
|
fill="transparent" stroke="#fff" stroke-width="1"
|
|
}}}
|
|
|
|
This is an abstract of the output:
|
|
|
|
<svg width="580px" height="580px" style="box-shadow:0 0 8px #000;">
|
|
<polyline points="230 580 230 380 195 251 151 174 109 132 75 113 49 106 32 106 21 109 ...
|
|
... 413 286 324 286 230 380 230 580 "
|
|
fill="transparent" stroke="#888" stroke-width="1">
|
|
</polyline>
|
|
</svg>
|
|
|
|
The complete ouput can be seen displayed in http://lambdaway.free.fr/lambdawalks/?view=fractal_tree
|