Code: Select all
' Turtle graphics
'
if device_type$()="iPad" then
t_init(0,50,100,100,600,600,.8,.8,.8,1,0,0)
else
t_init(0,30,20,20,300,300,.8,.8,.8,1,0,0)
end if
for i=1 to 12
for j=1 to 12 ! t_right(30) ! next j
t_turn(30,0)
next i
end
def t()
x=0 ! y=0 ! s=0 ! a=0
end def
def t_init(aa,ss,xt,yt,xb,yb,rb,gb,bb,rt,gt,bt)
graphics ! graphics clear ! option angle degrees
.xw=xb-xt ! .yw=yb-yt ! .xc=xt+.xw/2 ! .yc=yt+.yw/2
t.x=.xc ! t.y=.yc ! t.s=ss ! t.a=aa
fill color rb,gb,bb ! fill rect xt,yt to xb,yb
draw size 4 ! draw color 0,0,0 ! draw rect xt-2,yt-2 to xb+2,yb+2
draw color rt,gt,bt ! draw size 2
draw to t.x,t.y
end def
def t_move(nsteps)
dis=nsteps*t.s ! xdis=dis*cos(t.a) ! ydis=dis*sin(t.a)
t.x+=xdis ! t.y-=ydis
draw line to t.x,t.y
end def
def t_right(angle)
t.a-=angle ! t_move(1)
end def
def t_left(angle)
t.a+=angle ! t_move(1)
end def
def t_turn(angle,nsteps)
t.a+=angle ! t_move(nsteps)
end def