Sierpinski square curve: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) (Added 11l) |
|||
Line 335: | Line 335: | ||
{{out}} |
{{out}} |
||
See: [https://slack-files.com/T0CNUL56D-F016A7PQ8H5-c6c8571a24 sierpinski_square.svg] (offsite SVG image) |
See: [https://slack-files.com/T0CNUL56D-F016A7PQ8H5-c6c8571a24 sierpinski_square.svg] (offsite SVG image) |
||
# https://rosettacode.org/wiki/Sierpinski_square_curve |
|||
=={{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: {"X": "XF-F+F-XF+F+XF-F+F-X"}; |
|||
def sierpinski($count): |
|||
rules as $rules |
|||
| def p($count): |
|||
if $count <= 0 then . |
|||
else gsub("X"; $rules["X"]) | p($count-1) |
|||
end; |
|||
"F+XF+F+XF" | p($count) ; |
|||
def interpret($x): |
|||
if $x == "+" then turtleRotate(90) |
|||
elif $x == "-" then turtleRotate(-90) |
|||
elif $x == "F" then turtleForward(5) |
|||
else . |
|||
end; |
|||
def sierpinski_curve($n): |
|||
sierpinski($n) |
|||
| split("") |
|||
| reduce .[] as $action (turtle([200,650]) | turtleDown; |
|||
interpret($action) ) ; |
|||
sierpinski_curve(5) |
|||
| path("none"; "red"; 1) | svg(1000) |
|||
</lang> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |