This article introduces Turtle in Microsoft Small Basic programming language.

In this article:


What is a Turtle?

Turtle comes from Logo programming language. It's called Turtle Graphics. Basically to turn and to move the turtle causes graphic shapes.  Details about Turtle history is written in a TechNet Wiki article.

Turtle.Show()

This one-line code above shows the turtle like following picture.

Turtle Object

The Turtle object provides functionality do draw shapes like Logo programming language.

Properties

There are following four properties in Turtle object.

  • Angle - gets and sets the angle [degree] of the turtle.  The default value is 0.
  • Speed - gets and sets the speed (1 to 10) of the turtle.  The default value is 5.
  • X - gets and sets the X location of the turtle.  The default value is 320.
  • Y - gets and sets the Y location of the turtle.  The default value is 240.

Operations

There are following nine operations in Turtle object.  These operations don't return any values.

  • Hide() - hides the turtle.
  • Move(distance) - moves the turtle to a specified distance [pixel].
  • MoveTo(x, y) - turns and moves the turtle to the specified location.
  • PenDown() - sets the pen down.
  • PenUp() - sets the pen up.
  • Show() - shows the turtle.
  • Turn(angle) - turns the turtle by the specified angle [degree].
  • TurnLeft() - turns the turtle 90 degrees to the left.
  • TurnRight() - turns the turtle 90 degrees to the right.

Known Issues

There is a know issue that the turtle can't be shown if once hided.  This means that also the turtle graphics (trails) can be cleared only one time with GraphicsWindow.Clear().  But there is a workaround to remove the turtle and turtle trails.  The detail is written in a blog article.

Sample Code

' Turtle Object Code Sample
 
' Turtle.Show() operation
Turtle.Show()
 
' Turtle.PenUp() and Turtle.MoveTo() operations
Turtle.PenUp()
x = 320
y = 400
Turtle.MoveTo(x, y)
 
' Turtle.Angle property
Turtle.Angle = 45
 
' show properties
GraphicsWindow.BrushColor = "Gray"
GraphicsWindow.DrawText(10, 10, "Turtle.X=" + Turtle.X)
GraphicsWindow.DrawText(10, 30, "Turtle.Y=" + Turtle.Y)
GraphicsWindow.DrawText(10, 50, "Turtle.Angle=" + Turtle.Angle)
GraphicsWindow.DrawText(10, 70, "Turtle.Speed=" + Turtle.Speed)
Program.Delay(3000)
 
' Turtle.PenDown() operation
Turtle.PenDown()
GraphicsWindow.PenColor = "Red"
 
' Turtle.Move() operation
distance = 130
Turtle.Move(distance)
 
' Turtle.Turn() and Turtle.Move operations
angle = -90
Turtle.Turn(angle)
Turtle.Move(distance)
 
' Turtle.TurnRight() and Turtle.Move operations
Turtle.TurnRight()
Turtle.Move(distance)
 
' Turtle.TurnLeft() and Turtle.Move operations
Turtle.TurnLeft()
Turtle.Move(distance)
 
' Turtle.Hide() operation
Turtle.Hide()

Sample Programs

  • Another Turtle Graphics 0.5b (XVK119-3) - simple LOGO program
  • Brownian Motion (RFV485) - is a Brownian motion demo
  • Dragon and Turtle 0.6b (HMP803-5) - a fighting game
  • Hilbert Curve (CMN910) - draws a Hilbert curve
  • One Stroke Solver 0.2 (FST624-0) - solves one stroke path problem
  • Turtle Brick 0.1 (KDH145) - brick building with Turtle
  • Turtle Dodger 0.5b (QZN342-3) - simple game
  • Turtle Flash 0.3 (RBN002-1) - just shows flash animation
  • Turtle Maze 1.62 (PNC833-19) - maze game
  • Optical Illusion #01 (TQH071) - doesn't use Turtle object but image
  • Turtle Marionette (VTD423-0) - doesn't use Turtle object but image

Other Resources

See Also

Other Languages