Page 107 - Learn To Program With Scratch
P. 107
Draw side 1. The sprite ends up at point A
pointing right.
Drawing Plan door. The sprite ends up at point B pointing
roof Move horizontally 1 unit and draw the first
triangle parallelogram right.
Move horizontally 2 units (i.e., to point C)
and draw side 2. The sprite ends up at
point C pointing right.
E F Move horizontally 4 units (i.e., to point D)
side 1 side 2 and draw the second door. The sprite ends
up at point D pointing right.
door Move backward 7 units then up 5 units.
This puts the sprite at point E pointing right.
Draw the roof. The roof drawing procedure
A B C D will first draw the triangle, then move to
point F, and finally draw the parallelogram.
Figure 4-24: We can draw this house by dividing the task into several smaller pieces and
handling each piece individually .
On one hand, working on this simple problem allows us to focus on
the solution strategy without getting bogged down in a lot of detail. On the
other hand, despite its apparent simplicity, the problem lends itself to many
different solutions. Here are some possibilities:
• We can view the house as made up of straight lines. In this case, draw-
ing each line is a major task.
• We can view the house as made up of six independent shapes: side 1,
side 2, two doors, a triangle, and a parallelogram. Drawing each shape
constitutes a major task.
• Since the two doors are identical, we can define one major task for
drawing a door and invoke that task twice.
• We can view the triangle and the parallelogram at the top of the house
as one unit, the roof. In this case, one major task is to draw the roof.
• We can view side 1 and its door as one unit, the front side. In this case,
one major task is to draw the front side.
There are many other possibilities, but that’s enough to illustrate the
point. The idea is to group tasks into small, understandable pieces that
you can deal with and then focus on one piece at a time. If you find simi-
lar pieces, try to come up with a common solution and apply it to all those
pieces.
With that in mind, our plan for drawing the house is also outlined in
Figure 4-24. This plan assumes that the sprite starts facing right at point A.
All we need to do is create a script that matches the steps outlined in the
plan. We’ll write a procedure (called Side1) to draw the left side of the
house as specified in step 1. We will also write three procedures (called
Door, Side2, and Roof) to draw the two doors, the right side of the house,
and the roof (as specified in steps 2, 3, 4, and 6), and we will connect all
these procedures with appropriate motion commands.
Procedures 85
www.it-ebooks.info

