Dragon curve: Difference between revisions
→{{header|jq}}: L-system
(→{{header|Commodore BASIC}}: Added) |
(→{{header|jq}}: L-system) |
||
Line 3,073:
=={{header|jq}}==
{{works with|jq|1.4}}
'''Works with gojq, the Go implementation of jq'''
The programs given here generate SVG code that can be
viewed directly in a browser, at least if the file suffix is .svg.
The first program uses simple turtle graphics and an L-system;
the second is based on the fractalMakeDragon example in [[#Javascript|Javascript]].
===L-System===
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:
{ F: "F+S",
S: "F-S" };
def dragon($count):
rules as $rules
| def p($count):
if $count <= 0 then .
else gsub("S"; "s") | gsub("F"; $rules["F"]) | gsub("s"; $rules["S"])
| p($count-1)
end;
"F" | p($count) ;
def interpret($x):
if $x == "+" then turtleRotate(90)
elif $x == "-" then turtleRotate(-90)
elif $x == "F" then turtleForward(4)
elif $x == "S" then turtleForward(4)
else .
end;
def dragon_curve($n):
dragon($n)
| split("")
| reduce .[] as $action (turtle([200,300]) | turtleDown;
interpret($action) ) ;
dragon_curve(15)
| path("none"; "red"; "0.1") | svg(1700)</lang>
===fractalMakeDragon===
The following is based on the JavaScript example, with some variations, notably:
* the last argument of the main function allows CSS style elements to be specified
|