1 / 9

Turtle Graphics

Turtle Graphics. Turtle graphics provide a simple way to draw pictures in a window. The name suggests the way in which we can think about the drawing process.

rae-sears
Download Presentation

Turtle Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Turtle Graphics • Turtle graphics provide a simple way to draw pictures in a window. • The name suggests the way in which we can think about the drawing process. • Imagine a turtle walking around a screen with a pen tied to it’s tail. Commands tell it to move and to put the pen up and down (i.e. put it’s tail up and down.) • This is a primitive form of graphics but gives us a good introduction to graphic concepts.

  2. Example TurtleGraphics Program import TurtleGraphics.StandardPen; public class DrawSquare { public static void main(String [ ] args) { StandardPen pen = new StandardPen(); pen.up(); pen.move(25); pen.turn(90); pen.move(25); pen.down(); pen.turn(90); pen.move(50); pen.turn(90); pen.move(50); pen.turn(90); pen.move(50); pen.turn(90); pen.move(50); } }

  3. Example Program Explanation • Imports the TurtleGraphics package which allows us to draw basic shapes. • StandardPen is the class we will be using. import TurtleGraphics.StandardPen;

  4. Example Program Explanation pen.up(); pen.move(25); pen.turn(90); pen.move(25); pen.down(); • These statements lift the pen, move it to the square’s top left corner, and lower to set it to draw.

  5. Example Program Explanation pen.turn(90); pen.move(50); pen.turn(90); pen.move(50); pen.turn(90); pen.move(50); pen.turn(90); pen.move(50); • These statements draw a square with side length of 50 pixels. Each turn forms the 90° turn at the corners.

  6. Turtle Graphics Pen Messages

  7. Misc. Statements on Turtle Graphics • When the StandardPen is instantiated, it is always: • In the center of the graphics window • In the down position • Pointing North.

  8. Additional TurtleGraphics Features

  9. TurtleGraphics Color Constants • The Color class has a number of different colors available. • import java.awt.Color; • red • yellow • blue • orange • pink • cyan • magenta • black • white • gray • light gray • dark gray

More Related