Category talk:Jq-turtle: Difference between revisions
Content added Content deleted
(add preamble) |
(def turtleMove()) |
||
Line 29: | Line 29: | ||
def turtleDown: .up=false; |
def turtleDown: .up=false; |
||
# Move to $xy = [$x,$y] without changing orientation |
|||
⚫ | |||
def turtleMove($xy): |
|||
$xy as [$x, $y] |
|||
| .svg += "M \($x),\($y)"; |
|||
# Move to $xy = [$x,$y] in SVG co-ordinates and change orientation to ($angle % 360) degrees, |
|||
⚫ | |||
# but if $xy is not an array, then just adjust the orientation. |
|||
⚫ | |||
def turtleMove($xy; $angle): |
|||
⚫ | |||
if $xy|type == "array" |
|||
⚫ | |||
then $xy as [$x, $y] |
|||
⚫ | |||
| .svg += "M \($x),\($y)" |
|||
⚫ | |||
else . |
|||
⚫ | |||
⚫ | |||
| .angle = ($angle % 360); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
def turtleForward($d): |
def turtleForward($d): |
||
Line 56: | Line 51: | ||
elif .angle==180 then .svg += " m -\($d),0" |
elif .angle==180 then .svg += " m -\($d),0" |
||
elif .angle==270 then .svg += " m 0,\($d)" |
elif .angle==270 then .svg += " m 0,\($d)" |
||
else ($d * (.angle|cosDegrees)) as $dx |
else ($d * (.angle|cosDegrees|rnd)) as $dx |
||
| ($d * (.angle|sinDegrees) * -1) as $dy |
| ($d * (.angle|sinDegrees|rnd) * -1) as $dy |
||
| .svg += " m\($dx),\($dy)" |
| .svg += " m\($dx),\($dy)" |
||
end |
end |
||
Line 69: | Line 64: | ||
end |
end |
||
end; |
end; |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
|||
⚫ | |||
def svg($size): |
def svg($size): |
||
Line 81: | Line 97: | ||
path("none"; "red"; 1) | svg($size); |
path("none"; "red"; 1) | svg($size); |
||
################################################################################# |
|||
### |
|||
def svg($size): |
def svg($size): |