lambdaway
::
hilbert
5
|
list
|
login
|
load
|
|
{center {svg {@ width="580px" height="580px" style="box-shadow:0 0 8px #888;"} {path {@ d="M {turtle 10 10 0 {H5}}" {stroke 10 #888}}} {path {@ d="M {turtle 10 10 0 {H5}}" {stroke 4 #000}}} {path {@ d="M {turtle 10 10 0 {H5}}" {stroke 1 #fff}}} }} _h2 hilbert | [[hilb's world|?view=hilbert2]] | [[hilbert_chatgpt]] | [[fern]] | [[dragon]] _h2 1) two twinned recursive functions {prewrap '{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 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}}} -> {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}}} '{def H5 {left 18 5}} -> {def H5 {left 18 5}} } _p The word {code Tθ} rotates the drawing direction of a pen from {b θ} degrees and the word {code Md} moves it on {b d} pixels. _p The call {code '{left 18 5}} produces 2387 words begining with [{code 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 ...}] _h2 2) the SVG context _p Lambdatalk comes with a primitive, {code turtle}, translating the previous sequence of words into a sequence of SVG points [{code x0 y0 x1 y2 ... xn yn}] feeding the "d" attribute of a SVG path. {pre '{def stroke {lambda {:w :c} fill="transparent" stroke=":c" stroke-width=":w"}} -> {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}}} } }
lambdaway v.20211111