Search This Blog

Friday, January 21, 2011

Turtle Graphics

So in this tutorial I don't explain TurtleGraphics too much, but here is a text explanation. So the pen object in the code is like a real pen on paper. The pen.up() command picks the pen up from the paper so that it's not drawing. The pen by default starts out in the middle of the paper, so we move it to the corner by the following code until the pen.down() command. This command puts the pen on paper and allows the pen to draw. The rest of the code is explained in the video, but if you have any questions, feel free to ask.

download at:
http://turing.cs.wwu.edu/martin/Software%20Packages/TurtleGraphics/TurtleGraphics.zip

Source code:

import TurtleGraphics.StandardPen;

public class DrawSquare{
    public static void main(String[] args){
            StandardPen pen = new StandardPen();
          
            /* Lifts the pen, and moves it to top of square */
            pen.up();
            pen.move(25);
            pen.turn(90);
            pen.move(25);
            pen.down();
          
            // Draws square
            pen.turn(90); pen.move(50);
            pen.turn(90); pen.move(50);
            pen.turn(90); pen.move(50);
            pen.turn(90); pen.move(50);
                      
      
    }
}

No comments:

Post a Comment