A small update to the library. Added the filling function and the possibility to show the orientation of the turtle.
REM Simplified turtle commands for Yabasic 2.78.0, by Galileo, 5/2017. Rev. 12/2017.
REM Adapted from Tomaaz's turtle library.
export sub startTurtle() // Initialize turtle environment.
open window 850, 700
backcolor 0, 0, 0
clear window
home()
end sub
export sub move(long) // If positive, forward. Negative, backward.
local a, b, x, y
a = sin (angle * pi / 180) * long
b = cos (angle * pi / 180) * long
x = posx + a
y = posy - b
if draw then
line posx, posy, x, y
end if
posx = x
posy = y
end sub
export sub turn(degrees) // If positive, turn right. Negative, turn left.
angle = angle + degrees
if angle > 360 angle = angle - 360
if angle < 0 angle = angle + 360
end sub
export sub pen(state) // If 0, no draw. Another, draw.
draw = state // Global variable for this module.
end sub
export sub goxy (x, y) // Jump to location. No draw.
posx = x
posy = y
end sub
export sub gox (steps) // Jump steps pixels in x coord. No draw. Positive or negative.
posx = posx + steps
end sub
export sub goy (steps) // Jump steps pixels in y coord. No draw. Positive or negative.
posy = posy + steps
end sub
export sub reset () // Set angle to 0 degrees.
angle = 0 // Global variable for this module.
end sub
export sub posx() // Return turtle x location.
return posx
end sub
export sub posy() // Return turtle y location.
return posy
end sub
export sub angle() // Return turtle orientation.
return angle
end sub
export sub home() // Establish start mode.
reset()
posy = peek("winheight") / 2 // Global variable for this module.
posx = peek("winwidth") / 2 // Global variable for this module.
pen(1)
end sub
export sub arc(ang, radius) // Moves the turtle along an arc.
local i, stp, sgn
if ang < 0 then sgn = -1 else sgn = 1 end if
stp = (2 * pi * radius) / 360
for i = 1 to abs(ang)
move(stp)
turn(sgn)
next i
end sub
export sub infill(test$) // Fill irregular shapes
wid = peek("winwidth") : hei = peek("winheight")
floodFill(posx, posy, test$)
end sub
sub floodFill(x, y, test$)
if test$ <> getbit$(x, y, x, y) then
dot x, y
floodFill(x + 1, y, test$)
floodFill(x - 1, y, test$)
floodFill(x, y + 1, test$)
floodFill(x, y - 1, test$)
end if
end sub
export sub turtle() // show turtle orientation
color 255,0,0
pen(true)
move(10)
fill circle posx, posy, 2
end sub
A little example.
import turtle3
clear screen
startTurtle()
home()
goxy(100,600)
multiBatman()
// =====================
sub multiBatman()
local i
for i = 0.1 to 0.8 step 0.2
reset()
gox(i * 200) : goy(i * -50)
turn(i*100)
color 128 * i, 128 * i, 255
batman(i)
next i
end sub
sub batman(scale)
local ax, ay, angle, color$
ax = posx() : ay = posy()
hemibatman(1, scale)
goxy(ax, ay)
color$ = getbit$(ax,ay,ax,ay)
turn(-263)
hemibatman(-1, scale)
pen(false) : turn(90) : move(5) : pen(true)
infill(color$)
end sub
sub hemibatman(sign, scale)
turn(sign * 5)
draw(30, scale * 3, sign * 1)
draw(250, scale * 0.3, sign * 0.5)
turn(sign * 45)
draw(15, scale * -3, sign * 1)
draw(240, scale * -0.4, sign * 0.7)
draw(10, scale * -3, sign * 1)
turn(sign * 50)
draw(160, scale * 1, sign * -0.6)
draw(100, scale * 1, sign * -0.5)
draw(80, scale * 1, sign * -0.2)
turn(sign * 70)
draw(20, scale * -3, sign * 2)
draw(200, scale * -0.4, sign * 0.7)
move(scale * -40)
turn(sign * 30)
draw(71, scale * 0.8, sign * 0.8)
end sub
sub draw(reps, st, turn)
local i
for i = 1 to reps
move(st) : turn(turn)
next i
end sub