Microsoft Small Basic

Program Listing: QLM601
'-----------------------
' Author: Naggingmachine
' Blog: http://naggingmachine.tistory.com
' Email: wooseok.seo@gmail.com
'-----------------------

'-----------------------
' Timer setup
'-----------------------
Timer.Interval = 50
Timer.Tick = onTimerTick


'-----------------------
' Mouse setup
'-----------------------
GraphicsWindow.MouseMove = onMouseMove
mouseX = GraphicsWindow.MouseX
mouseY = GraphicsWindow.MouseY



'-----------------------
' Turtle setup
'-----------------------
turtleX = GraphicsWindow.Width/2
turtleY = GraphicsWindow.Height/2
Turtle.X = turtleX
Turtle.Y = turtleY
Turtle.Show()


'-----------------------
' Initialize
'-----------------------
GraphicsWindow.Title = "Having fun with Turtle"
GraphicsWindow.BrushColor = GraphicsWindow.GetColorFromRGB(127,127,127)
GraphicsWindow.FontName="arial"
GraphicsWindow.FontSize=30
GraphicsWindow.Fontbold="true"
GraphicsWindow.DrawText(0, 0, "Move mouse, then the turtle will follow you.")

moveHorizontal = 5
moveVerticle = 5

Sub onTimerTick

' Get the new X position of the turtle
If (mouseX < turtleX) Then
If (turtleX - mouseX < 5) Then
turtleX = mouseX
Else
turtleX = turtleX - moveHorizontal
EndIf
ElseIf (mouseX > turtleX) Then
If (mouseX - turtleX < 5) Then
turtleX = mouseX
Else
turtleX = turtleX + moveHorizontal
EndIf
EndIf

' Get the new Y position of the turtle
If (mouseY < turtleY) Then
If (turtleY - mouseY < 5) Then
turtleY = mouseY
Else
turtleY = turtleY - moveVerticle
EndIf
ElseIf (mouseY > turtleY) Then
If (mouseY - turtleY < 5) Then
turtleY = mouseY
Else
turtleY = turtleY + moveVerticle
EndIf
EndIf

' Move the turtle to new position
Turtle.X = turtleX
Turtle.Y = turtleY

EndSub

Sub onMouseMove
mouseX = GraphicsWindow.MouseX
mouseY = GraphicsWindow.MouseY
EndSub