Hilbert curve: Difference between revisions
Content added Content deleted
(Added solution for Action!) |
|||
Line 1,878: | Line 1,878: | ||
return main(); |
return main(); |
||
})();</lang> |
})();</lang> |
||
=={{header|jq}}== |
|||
{{works with|jq}} |
|||
'''Works with gojq, the Go implementation of jq''' |
|||
The program given here generates SVG code that can be |
|||
viewed directly in a browser, at least if the file suffix is .svg. |
|||
See [[Peano_curve#Simple_Turtle_Graphics | Simple Turtle Graphics]] |
|||
for the simple-turtle.jq module used in this entry. The `include` |
|||
statement assumes the file is in the pwd. |
|||
<lang jq>include "simple-turtle" {search: "."}; |
|||
def rules: |
|||
{ A: "-BF+AFA+FB-", |
|||
B: "+AF-BFB-FA+" }; |
|||
def hilbert($count): |
|||
rules as $rules |
|||
| def p($count): |
|||
if $count <= 0 then . |
|||
else gsub("A"; "a") | gsub("B"; $rules["B"]) | gsub("a"; $rules["A"]) |
|||
| p($count-1) |
|||
end; |
|||
"A" | p($count) ; |
|||
def interpret($x): |
|||
if $x == "+" then turtleRotate(90) |
|||
elif $x == "-" then turtleRotate(-90) |
|||
elif $x == "F" then turtleForward(5) |
|||
else . |
|||
end; |
|||
def hilbert_curve($n): |
|||
hilbert($n) |
|||
| split("") |
|||
| reduce .[] as $action (turtle([0,5]) | turtleDown; |
|||
interpret($action) ) ; |
|||
hilbert_curve(5) |
|||
| path("none"; "red"; 1) | svg(170) |
|||
</lang> |
|||
{{out}} |
|||
https://imgur.com/a/mJAaY6I |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |