Page 255 - Learn To Program With Scratch
P. 255
n o t e The idea of this program is adapted from Daniel Watt’s Learning with Logo
(McGraw-Hill, 1983). You’ll find the full word lists we’re using in the Scratch file
for this project, Poet.sb2.
Each poem is composed of three lines that follow these patterns:
• Line 1: article, adjective, noun
• Line 2: article, noun, verb, preposition, article, adjective, noun
• Line 3: adjective, adjective, noun
With those constructions in mind, let’s look at the procedure that
builds the first line of the poem, shown in Figure 9-26.
Figure 9-26: “Writing” the first line of a poem
This script selects a random word from the article list and stores it in line1.
Then the script appends a white space, a random word from the adjective
list, another white space, and a random word from the noun list. Finally, the
poet sprite says the complete line. I don’t show the procedures for the other
two lines of the poem here because they’re very similar, but you can open
up Poet.sb2 to view them.
Here are two poems created by our machine poet:
each glamorous road
a fish moves behind each white home
calm blue pond
every icy drop
a heart stares under every scary gate
shy quiet queen
try it out 9-8
Poet .sb2 Open Poet.sb2 and run it several times to see what this machine poet is capable of
authoring . Then change the program so that it uses three sprites, with each sprite
responsible for one line of the poem, allowing you to read the whole poem on the
Stage at once .
Lists 233
www.it-ebooks.info

