'Turtle Logo in Small Basic
'by Harry Hardjono
'Turtle angle speed x1 y1 x0 y0
'Turtle move moveto penup pendown
'Turtle turn turnleft turnright
' Only took me 1 hour to do this. :)
'
GraphicsWindow.Show()
GraphicsWindow.Clear()
cmd1="init"
Toitle()
cmd1="move"
cmd2="50"
Toitle()
cmd1="turnright"
cmd2="90"
Toitle()
cmd1="move"
cmd2="50"
Toitle()
cmd1="turnright"
cmd2="90"
Toitle()
cmd1="move"
cmd2="50"
Toitle()
cmd1="turnright"
cmd2="90"
Toitle()
cmd1="move"
cmd2="150"
Toitle()
cmd1="turnleft"
cmd2="90"
Toitle()
cmd1="move"
cmd2="50"
Toitle()
cmd1="turnright"
cmd2="90"
Toitle()
cmd1="moveto"
cmd2="20"
cmd3="50"
Toitle()
cmd1="turn"
cmd2="20"
Toitle()
cmd1="move"
cmd2="1500"
Toitle()
cmd1="turnright"
cmd2="100"
Toitle()
cmd1="move"
cmd2="1500"
Toitle()
cmd1="turnright"
cmd2="100"
Toitle()
cmd1="move"
cmd2="1500"
Toitle()
cmd1="turnright"
cmd2="100"
Toitle()
cmd1="move"
cmd2="1500"
Toitle()
Sub Toitle
'cmd1=command (input)
'cmd2=param1 (input)
'cmd3=param2 (input)
If (cmd1="init") then
sy=GraphicsWindow.Height
sx=GraphicsWindow.Width
x1=sx/2
y1=sy/2
x0=x1
y0=y1
p=1
angle=90
elseif (cmd1="penup") then
p=0
elseif (cmd1="pendown") then
p=1
elseif (cmd1="move") then
'forward
x0=x1
y0=y1
x1=x0+cmd2*Math.Sin(Math.GetRadians(angle))
y1=y0+cmd2*Math.Cos(Math.GetRadians(angle))
draw()
elseif (cmd1="moveto") then
x0=x1
y0=y1
x1=cmd2
y1=cmd3
draw()
elseif (cmd1="turn") then
angle=cmd2
elseif (cmd1="turnleft") then
angle=angle+cmd2
elseif (cmd1="turnright") then
angle=angle-cmd2
endif
'These really need to be Mod
'Seems buggy - doesn't work with negative number?
RemBugFix2()
x1=Math.Remainder(x1,sx)
y1=Math.Remainder(y1,sy)
angle=Math.Remainder(angle,360)
endsub
Sub RemBugFix
While (px<0)
px=px+sx
EndWhile
While (py<0)
py=py+sy
EndWhile
endsub
Sub RemBugFix2
While (x1<0)
x1=x1+sx
EndWhile
While (y1<0)
y1=y1+sy
EndWhile
While (angle<0)
angle=angle+360
EndWhile
endsub
'Draw
Sub Draw
If (p>0) then
If (x0<>x1 or y0<>y1) then
m=math.Max(math.Abs(x1-x0),math.Abs(y1-y0))
mx1=0
mx3=m
For i=0 To m
my1=x0
my3=x1
mx2=i
map()
px=my2
my1=y0
my3=y1
mx2=i
map()
py=my2
RemBugFix()
px=Math.Remainder(px,sx)
py=Math.Remainder(py,sy)
GraphicsWindow.SetPixel(px,py,"blue")
EndFor
endif
endif
endsub
'map function
Sub map
'x1-x2-x3 y1-y2-y3
'(x2-x1)/(x3-x1)=(y2-y1)/(y3-y1)
'(y3-y1)*(x2-x1)/(x3-x1)=(y2-y1)
'y1+(y3-y1)*(x2-x1)/(x3-x1)=y2
my2=((my3-my1)*(mx2-mx1)/(mx3-mx1))+my1
EndSub
No comments:
Post a Comment