Project Folders
Teacher Resources
Student Resources
How Do I?
Site Map
Our Team
How can I create new turtle shapes with the click of a button?
Sometimes we'd like to be able to create new turtle shapes easily while a project is in use. For instance, it can be fun to click a button to capture a design which has just been created and turn this design into an animated turtle shape. This capability can be especially useful in projects posted on the web, which cannot access the graphics tab or the edit menu.

Vocabulary: snapshape


This project draws random snowflakes and saves one at a time into a turtle shape. (The code for make_flake is not provided here because that is not the point of the demonstration.) In this project, the background has been set to a blue color and frozen so that clean returns the background to solid blue.
Right-click HERE to Download

Notes:  In this project, the turtle begins as an empty shape, 120 by 120 pixels. (You may set your original turtle shape to dimensions suitable for the purpose of your project.) We hide the turtle while it draws a new snowflake. Let us look at the save_shape procedure, line by line:

Snapshape cuts the background underneath the turtle (even if it is hidden) and pastes it into the turtle's shape, replacing the original turtle shape. Following the snapshape command, the background area under the turtle is empty (white); since the background was frozen (with freezebg), clean returns the background to its original solid blue color.

st (show turtle) lets us see the new turtle shape.

In this project, the animate procedure sets the new turtle shape in motion.

You may wish to preserve more than one newly-created turtle shape, or you may wish to be able to reset the turtle to its original shape. This takes some advance planning: you need to set a number of shapes to the desired shape ahead of time. In the next sample project, a number of turtle shapes have been preset to the shape of a rectangular outline.

Right-click HERE to Download
Drag the rectangle over a flower. Click the snapshape button: the turtle wears the shape of the flower. Now click the garden button!

Notes:  The startup procedure is run automatically when the project opens. snapshot saves the background of the page in the computer's memory. In the reset procedure, restore replaces the current background with the original background preserved with snapshot. setsh shape + 1 sets the turtle to the next shape number (another rectangle) so that it is ready to be dragged over another flower. setpos [0 14] returns the turtle to its starting position.

The garden procedure erases the background with clean and then stamps 20 turtle shapes in random positions. (See random.)

« Previous
Next »

© copyright 2001 - 2012  OpenWorld Learning.   All rights reserved.