Dragon curve: Difference between revisions

adding lambdatalk
(adding lambdatalk)
Line 2,958:
DragonCurve(14).isVisible = true
}</lang>
 
=={{header|Lambdatalk}}==
<lang scheme>
1) two twinned recursive functions
 
{def dcr
{lambda {:step :length}
{let { {:step {- :step 1}}
{:length {/ :length 1.41421}}
} {if {> :step 0}
then T45
{dcr :step :length}
T-90
{dcl :step :length}
T45
else T45
M:length
T-90
M:length
T45}
}}}
-> dcr
{def dcl
{lambda {:step :length}
{let { {:step {- :step 1}}
{:length {/ :length 1.41421}}
} {if {> :step 0}
then T-45
{dcr :step :length}
T90
{dcl :step :length}
T-45
else T-45
M:length
T90
M:length
T-45}
}}}
-> dcl
 
The word Tθ rotates the drawing direction of the pen from θ degrees
and the word Md moves it on d pixels.
Writing {dcr 10 360} outputs 4093 words begining with
T45 T45 T45 T45 T45 T45 T45 T45 T45 T45 M11.250283388970585
T-90 M11.250283388970585 T45 T-90 T-45 M11.250283388970585 T90 M11.250283388970585 ...
 
2) the SVG context
 
Lambdatalk comes with a primitive, turtle, translating the previous sequence of words into
a sequence of SVG points [x0 y0 x1 y2 ... xn yn] feeding the "d" attribute of a SVG path.
 
3) drawing three dragon curves [2,6,10] of decreasing width:
 
{svg
{@ width="580px" height="580px"
style="box-shadow:0 0 8px #888;"}
{path {@ d="M {turtle 130 130 0 {dcr 2 360}}" {stroke 20 #ccc}}}
{path {@ d="M {turtle 130 130 0 {dcr 6 360}}" {stroke 10 #888}}}
{path {@ d="M {turtle 130 130 0 {dcr 10 360}}" {stroke 1 #000}}}
}
 
where
{def stroke
{lambda {:w :c}
fill="transparent" stroke=":c" stroke-width=":w"}}
-> stroke
 
The output can be seen in http://lambdaway.free.fr/lambdawalks/?view=dragon
</lang
 
=={{header|Liberty BASIC}}==