Working with Words 1

Basics Joining Words Labels on Screen

Basics

Type or cut and paste this code into the command line

print [hello world]

This is the easiest way to get the machine to output a line of text.

Type or cut and paste this code into the command line

repeat 4 [print [hello world]]

This just does it 4 times instead of once!

Joining Words Together.

Type or cut and paste this code into the command line

make "w1 "hello make "w2 "world

Hit return and then type in:

show word :w1 :w2

Then try:

show sentence :w1 :w2

Open the editor and paste in this procedure.

to talkrubbish
make "wd1 "Hello
ifelse ((random 10)>4) [make "wd2 "ugly] [make "wd2 "gorgeous]
ifelse ((random 10)>4) [make "wd3 "go] [make "wd3 "come]
ifelse ((random 10)>4) [make "wd4 "away] [make "wd4 "home]
show (sentence :wd1 :wd2 :wd3 :wd4)
end

Save and exit from the editor and then type talkrubbish into the command line.

Convince yourself that there are 8 possible answers! That is 23 combinations

Writing Labels to the Screen.

Type or cut and paste this code into the command line

cs label "hello

You should have hello written up the screen

Now try:

cs rt 90 label "hello

"hello" should now be horizontal.

show sentence :w1 :w2



Try this code:

cs pu repeat 20 [setxy repcount*20 repcount*5 rt 20 label "hello]


setxy puts the turtle at point x,y on the screen.
repcount counts how many times the repeat loop has been executed.

You can alter the font using the set and Label Font menu.


You could set the font and colour in the middle of a procedure by using setfontlabel to set the font and setpc to set the pencolour. Setting the pen colour is easy but you need to look at the help file to get at the 12 different numbers needed to control the font!

You can print the value of a variable by placing it after the label command.

cs pu repeat 20 [fd 30*(1+repcount/20) rt 20 label repcount]


Last updated 23rd February 2010