Koch curve: Difference between revisions

No edit summary
Line 876:
return main();
})();</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: "."};
 
def rules:
{ F: "F+F--F+F",
"": "F--F--F" };
 
def koch($count):
rules as $rules
| def repeat($count):
if $count <= 0 then .
else gsub("F"; $rules["F"])
| 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(4)
else .
end;
 
def koch_curve($n):
koch($n)
| split("")
| reduce .[] as $action (turtle([0,300]) | turtleDown;
interpret($action) ) ;
 
koch_curve(5)
| draw(1200)</lang>
 
 
=={{header|Julia}}==
2,467

edits