Turtle Graphics Environment


Turtle Graphics

In 1967, Seymour Papert and other researchers at MIT developed the programming language LOGO. LOGO was specifically designed to teach children how to program and solve problems on the computer. Central to the LOGO approach is the use of "turtle graphics", where the child/programmer draws pictures by moving an object (called a turtle) around on the screen. Simple commands such as "move forward 100 steps" and "turn right 90 degrees" are used to control the turtle, which leaves a trail (i.e., a line) in its wake.

This Web page contains a simple Turtle Graphics environment. In the top half of the page there is a box in which commands can be entered for controlling the movement of the turtle. When the button to the right is clicked, these commands are then executed and the turtle moves accordingly in the graphics screen below. The graphics screen is 400 units wide and 250 units tall, where each unit is a single pixel (dot) on the screen. The center of the screen is considered to be coordinate (0,0), so the x-axis (horizontal) ranges from -200 to 200 while the y-axis (vertical) ranges from -125 to 125. When you first load the page, the turtle is located at the center of the screen (0,0) facing straight up. You can't see the turtle itself, but you can follow its trail as it moves around on the screen. The coordinates of the turtle, along with its current heading (0 = up, 90 = right, 180 = down, etc.) and distance from the origin, are also displayed to the right. Functions for controlling the turtle's movement include:

forward: moves the turtle the specified number of steps in the direction it is currently facing. For example, forward(20) moves 20 steps forward.

left: turns the turtle the specified number of degrees to the left, relative to the current heading. For example, left(90) makes a right-angle turn to the left.

right: turns the turtle the specified number of degrees to the right, relative to the current heading. For example, right(90) makes a right-angle turn to the right.

Each time the "Execute code" button is clicked, the turtle will move according to the function calls in the large box at the top of the page. By default, each new drawing will begin where the previous one ended, although you can force all drawings to start at the center by checking the box labeled "Start each drawing at (0,0)". The lines drawn by the turtle will persist between executions until the "Reset graphics screen" button is clicked.

Post a Comment

Post a Comment (0)

Previous Post Next Post