Page 109 - Learn To Program With Scratch
P. 109
Figure 4-26: Procedures for drawing the house in Figure 4-24
Building Up with Procedures
FlowerFlake .sb2 Another way to deal with a large problem is to focus on the smaller details
first. If you solve a large problem’s smaller pieces (or find solutions that
already exist), you can then assemble the results from the bottom up to
reach a total solution.
To demonstrate this problem-solving technique, let’s start with a simple
procedure (called Leaf) that draws a single leaf as shown in Figure 4-27.
The procedure contains a repeat loop that runs twice to draw the two
halves of the leaf. Each half is drawn as a series of 15 short line segments
with a 6° turn angle between them. This is similar to the method of draw-
ing polygons we used in Chapter 2.
To draw the two
halves of the leaf.
Draw one Initial (and
half of the final) direction
leaf. of sprite.
An enlarged view of the
Turn 90˚ to prepare leaf drawn by this script.
for drawing the other
half.
Figure 4-27: The Leaf procedure and its output
Procedures 87
www.it-ebooks.info

