Hilbert curve: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 1,603: | Line 1,603: | ||
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
||
.__. .__. .__. .__. .__. .__. .__. .__. .__. .__. .__. .__. .__. .__. .__. .__. </pre> |
.__. .__. .__. .__. .__. .__. .__. .__. .__. .__. .__. .__. .__. .__. .__. .__. </pre> |
||
=={{header|Lambdatalk}}== |
|||
The output is visible in [http://lambdaway.free.fr/lambdawalks/?view=hilbert Hibert curve] |
|||
<lang Scheme> |
|||
1) two twinned recursive functions |
|||
{def left {lambda {:d :n} |
|||
{if {< :n 1} |
|||
then |
|||
else T90 {right :d {- :n 1}} |
|||
M:d T-90 {left :d {- :n 1}} |
|||
M:d {left :d {- :n 1}} |
|||
T-90 M:d {right :d {- :n 1}} |
|||
T90}}} |
|||
{def right {lambda {:d :n} |
|||
{if {< :n 1} |
|||
then |
|||
else T-90 {left :d {- :n 1}} |
|||
M:d T90 {right :d {- :n 1}} |
|||
M:d {right :d {- :n 1}} |
|||
T90 M:d {left :d {- :n 1}} |
|||
T-90}}} |
|||
The word Tθ rotates the drawing direction of a pen from θ degrees and the word Md moves it on d pixels. |
|||
{def H5 {left 18 5}} |
|||
The call {def H5 {left 18 5}} produces 2387 words begining with [T90 T-90 T90 T-90 T90 M10 T-90 M10 T-90 M10 T90 M10 T90 T-90 M10 T90 M10 T90 M10 T-90 M10 T-90 M10 T90 M10 T90 M10 T-90 T90 M10 T90 M10 T-90 M10 T-90 ...] |
|||
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. |
|||
{def stroke |
|||
{lambda {:w :c} |
|||
fill="transparent" stroke=":c" stroke-width=":w"}} |
|||
{svg |
|||
{@ width="580px" height="580px"} |
|||
{path {@ d="M {turtle 10 10 0 {H5}}" {stroke 8 #000}}} |
|||
{path {@ d="M {turtle 10 10 0 {H5}}" {stroke 4 #000}}} |
|||
{path {@ d="M {turtle 10 10 0 {H5}}" {stroke 1 #fff}}} |
|||
} |
|||
</lang> |
|||
=={{header|Lua}}== |
=={{header|Lua}}== |