Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Beginning Programming for Dummies 2004.pdf
Скачиваний:
109
Добавлен:
17.08.2013
Размер:
8.05 Mб
Скачать

166 Part III: Advanced Programming with Liberty BASIC

To save space, you can cram all the preceding lines together, as follows:

PRINT #main, “HOME; DOWN; NORTH; GO 35; TURN 225”

Another way to break up one long line into smaller, easier-to-read short lines is to use the underscore (_) character, which tells Liberty BASIC, “If you see the underscore character, treat the following line as if it’s tacked on to the end of the line containing the underscore character.”

So instead of writing the following:

PRINT #main, “HOME; DOWN; NORTH; go 35; TURN 225”

You can divide this line into smaller, separate lines, as in the following example:

PRINT #main, “HOME; DOWN; _

NORTH; GO 35; TURN 225”

For a faster way to draw a line, use the GOTO command following a DOWN command, as follows:

PRINT #MAIN, “DOWN; GOTO x y”

This line tells the computer to put down the pen and draw a line from the current turtle (pen) position to the X and Y coordinates that x and y, respectively, define.

Defining line thickness

For variety, you can alter the thickness of your lines. To change line thickness, use the SIZE command, as follows:

PRINT #Windowhandle, “size X”

Here’s what’s happening in this example:

1.The #Windowhandle portion defines the graphics window to adjust the thickness of the next lines that turtle graphics draw.

2.The size X command defines line thickness, where X is a number such as 3 or 8. If you don’t use the size command, the default thickness of a line is one (1).

Chapter 12: Drawing Pictures and Making Noise 167

To see how changing the thickness of a line works, try the following program, which creates two parallel lines of line thickness: five (5) and ten (10):

NOMAINWIN

WindowHeight = 300

WindowWidth = 250

OPEN “Graphics window” FOR Graphics AS #main

PRINT #main, “HOME; DOWN; NORTH”

PRINT #main, “SIZE 5”

PRINT #main, “GO 35; TURN 90; UP; GO 35; TURN 90”

PRINT #main, “SIZE 10”

PRINT #main, “DOWN; GO 35”

PRINT #main, “FLUSH”

PRINT #main, “trapclose [quit]”

WAIT

[quit]

CONFIRM “Are you sure you want to quit?”; quit$ IF quit$ = “no” THEN WAIT

CLOSE #main END

Defining line colors

Because drawing black lines can get tedious after a while, you may want to change the color of your lines. To change colors, you just need to use the COLOR command, as follows:

PRINT #Windowhandle, “COLOR color”

Here’s what’s happening in this example:

1.The #Windowhandle portion defines the graphics window to change the color of lines that turtle graphics draw.

2.The COLOR color command defines the color of the line, where color is one of the following: black, blue, brown, cyan, darkblue, darkcyan, darkgray, darkgreen, darkpink, darkred, green, lightgray, palegray, pink, red, white, and yellow.

To see how changing the color of a line works, try the following program, which adds color to two parallel lines: