4. First Steps <<< Contents >>> 6. The Garden with Repetitions
After the first steps, we will teach Peter how to plant his own garden. We will continue editing the Test program. We will add a picture of a flower, and tell Peter to plant the flower during his walk.
First, we will prepare the picture of the
flower. We will use an empty square, into which we will draw the
flower. Look at the Global
Variables and Functions
window. In the basic
variables and functions group,
there is an empty
square icon. Using the right mouse button, drag
the icon under all of the elements in the group.
This creates a copy of the element with the name of empty square 2. Click the icon to select the element (it will be marked by a rectangle). Click the text beside the icon. The text will be framed, and there will be a blinking cursor. Type Flower as the new element name, and then press Enter. This creates (declares) a new item called Flower.
Now we will draw the picture of the flower. Double-click the Flower icon. An enlarged picture of the empty square appears in the editing window. You can draw the flower using the following steps.
On the toolbar, there is a drop-down list
of the graphical editor functions. Another drop-down list enables
you to select line thickness. Choose the Sphere
drawing function. At the bottom of the editing window, there is a
color pick-list. Click the red color (the topmost one). At the
top of the picture, approximately in the middle, click and hold
the left mouse button, and drag the mouse towards the middle of
the picture. Release the button. The red sphere will be the
bloom. Pick a dark green color (the second from the bottom) with
the left mouse button, and in the functions list, choose Line
.
Draw one line downwards from the sphere and then two lines on the
sides. These will represent the leaves. The result could look
like this (maybe a dahlia?):
When you finish drawing, return to editing
the main program function by double-clicking its icon (it should
still be called Test). If you want to get back to the elements that you
edited before, you can use the Previous Edit and Next Edit
buttons that enable you to scroll through the history of the
edited elements.
Let us assemble the new program. In the previous chapter, we have left it in a state, in which Peter took one step, turned to the left, repeated both of the commands for three more times, stopped, and waited for a key to be pressed.
Take one more look into the group with
commands for Peter. You can find it in the upper right window
called Basic
Elements, Trash, and it is
called Peter. The sixth element from the top is item in front of Peter .
Drag this element in the uppermost place in the program, in front
of the first command. When you drop this element, an equals sign
appears in front of it.
By this, the editor informs you that the element requires a
parameter. This parameter will be the flower we have created.
In the Global Variables and Functions window, drag the Flower item towards the item in front of Peter
element, so that the upper left corner of the element you drag
gets over the bottom right corner of the destination element.
During dragging, you may notice that when you are close to the item in front of Peter element, a selection rectangle appears around its
text. The destination element signals in this way that you can
drop the element there. It is a basic feature of the elements
that you can only create combinations that make sense. You cannot
assemble nonsense (automatic syntax).
When you connect the flower item, the equals sign disappears. The item in front of Peter element has its parameter, and is satisfied now. We have created a small branch consisting of two elements, whose meaning is laying the flower in front of Peter. Copy the branch three times before the remaining step commands (by dragging the item in front of Peter element with the right mouse button). As a result, you should have this program:
Start the program. Peter plants four flowers and stops on his original position. One must admit that he steps on the flowers, but we should forgive him. He is just learning how to take care of his garden.
4. First Steps <<< Contents >>> 6. The Garden with Repetitions