LOGO Programming


How to "Roll the Dice"

It's really fun to see if you can get the Turtle to do what you want it to do, but it's also fun to have the turtle "make up his own mind". There is a word in logo (RANDOM) that will pick a number for you. You can use RANDOM anyplace you need to use a number in your program. This program prints random numbers between 0 and 11.

REPEAT 20 [PRINT RANDOM 12]

Let's use RANDOM to draw lines all over the screen:

TO LINES
    REPEAT 100 [SETXY RANDOM 200 RANDOM 200]
END

We can also make "random" music:

TO SONG
    REPEAT 24 [NOTE RANDOM 12]
END

We can even make a "picture" of the music:

TO SONG2
    REPEAT 24 [PLAYDRAW RANDOM 12 REPCOUNT]
END

TO PLAYDRAW :NOTE :WHERE
    SETXY :WHERE*12 :NOTE*12
    NOTE :NOTE
END