Sierpinski arrowhead curve: Difference between revisions

(Added 11l)
Line 717:
dc.SavePNG("sierpinski_arrowhead_curve.png")
}</lang>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
 
This entry uses an L-system and turtle graphics to generate an SVG
file, which can be viewed using a web browser, at least if the file type is `.svg`.
 
See [[Category_talk:Jq-turtle]] for the turtle.jq module used here.
Please note that the `include` directive may need to be modified
depending on the location of the included file, and the command-line
options used.
<lang jq>include "turtle" {search: "."};
 
# Compute the curve using a Lindemayer system of rules
def rules:
{X: "Yf+Xf+Y", Y: "Xf-Yf-X", "": "X"};
 
def sierpinski($count):
rules as $rules
| def repeat($count):
if $count == 0 then .
else ascii_downcase | gsub("x"; $rules["X"]) | gsub("y"; $rules["Y"])
| repeat($count-1)
end;
$rules[""] | repeat($count) ;
 
def interpret($x):
if $x == "+" then turtleRotate(60)
elif $x == "-" then turtleRotate(-60)
elif $x == "f" then turtleForward(3)
else .
end;
 
def sierpinski_curve($n):
sierpinski($n)
| split("")
| reduce .[] as $action (
turtle([0,-350]) | turtleDown | turtleRotate(60);
interpret($action) ) ;
 
# viewBox = <min-x> <min-y> <width> <height>
# Input: {svg, minx, miny, maxx, maxy}
def svg:
"<svg viewBox='\(.minx|floor) \(.miny - 4 |floor) \(.maxx - .minx|ceil) \(6 + .maxy - .miny|ceil)'",
" preserveAspectRatio='xMinYmin meet'",
" xmlns='http://www.w3.org/2000/svg' >",
path("none"; "red"; 1),
"</svg>";
 
sierpinski_curve(8)
| svg
</lang>
 
 
=={{header|Julia}}==
2,465

edits