prev | TOC | next

A Personalized Turtle

files: (help)

You should now have enough knowledge about programming to create your own turtle that does something unique.  In this lesson you will create a turtle that prints your name.  This will give you experience moving the turtle and getting a feel for how to turn it and make it draw a pattern.

Examine the Bob turtle referenced at the top of this lesson.  As written, it is a bit long and a bit repetitive.  We'll learn how to solve that later using loops.  Right now this is the most straightforward way to draw "Bob."

If you haven't done so already, run the turtle by clicking the green Run button.  You should see something like this in the Display tab.  Creating letters out of straight line segments won't win any awards in penmanship, but at least it is recognizable.

When using Turtle Graphics to draw something, the two most important things to keep in mind are: (1) where the turtle is on the display and (2) where it is heading.  When the turtle starts running it is in the center of the display area pointing North (or up).  As you use the commands forward(), backward(), left() and right(), you need to  keep track of where you are and  where you are pointing.

Examine the code in Bob's runTurtle() method and study how it draws its name.  When you are ready, create your own turtle  and see if you can draw your name using Jurtle's Turtle Graphics.

Creating your personal Turtle

Choose File->New->New Turtle... from Jurtle's menus.  When the dialog comes up asking you to enter a name, type your first name (or whatever name you want to give it).  There is a common convention that Java class names (i.e., the Turtle's name) should start with an uppercase letter.  So if your name is Fred, enter "Fred" rather than "fred."  After entering the name, click the OK button (or press the Enter key).  The display should look similar to below.

All the drawing commands need to be placed in the runTurtle() method between its opening "{" and closing "}".   Remember, this is the method that is automatically called by the Jurtle system when you run the turtle.  You will enter your drawing commands under or in place of the comment line that says "Add your drawing command here."  You must be sure to end every command (technically called a statement) with a semicolon.  If you don't, you will get compilation errors when you run the Turtle.

Don't try to create your whole name at first; just do a couple of line segments to get the feel of things.  After entering a few commands such as forward(), right(), etc.,  run the Beautify menu item to make sure your code is formatted correctly.  All the statements you entered should be indented to the same level.  If they aren't, you should check to see if you forgot to put a semicolon after the line above the misaligned one.  Leaving out an opening or closing parenthesis will also cause formatting problems.

After entering your drawing commands and beautifying to make sure everything is lined up properly, click the Compile button in the toolbar.  If the code successfully compiled, you will remain in the Edit view and the highlighted class name in the Turtle list will become un-italicized.  However, if you have errors, the view will switch to the Errors tab and the error messages from the compiler will be displayed.  These messages can appear cryptic at first, but start at the top and see what it thinks is wrong.  Here are some common problems you might encounter:

  • misspelling a command name (e.g., foward(10) rather than forward(10))
  • leaving out a parameter to a command (e.g., forward() rather than forward(10))
  • forgetting to type a close parenthesis after the last parameter in the command

If you double-click on an error line in the Errors tab, you will be switched back to the Edit tab and the offending line will be highlighted.  You can make the appropriate changes and then compile again.

When the Turtle compiles without errors, run it by clicking the Run button.  If it draws what you were attempting then congratulations!  Add more commands until you have your entire name drawn.  If it draws something but it was not what you intended, go back to your code and figure out what it is doing wrong.

After getting the basic name drawn, you can embellish it by changing the pen width, pen color, or background color.