19.04.2017 Views

Learn to Program with Small Basic

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

NOTE <strong>Program</strong>mers usually use one-letter variables <strong>to</strong> name the loop’s counter (such as I, J,<br />

or K), but any other name works <strong>to</strong>o. It doesn’t matter if you use upper- or lowercase<br />

letters—<strong>Small</strong> <strong>Basic</strong> would treat I and i as the same variable.<br />

TRY IT OUT 5-2<br />

Predict the output of the following program. Then run the program <strong>to</strong> check your<br />

answer.<br />

GraphicsWindow.PenColor = "Red"<br />

GraphicsWindow.PenWidth = 3<br />

For I = 1 To 4<br />

Turtle.Move(30)<br />

Turtle.Turn(-60)<br />

Turtle.Move(30)<br />

Turtle.Turn(120)<br />

Turtle.Move(30)<br />

Turtle.Turn(-60)<br />

Turtle.Move(30)<br />

Turtle.TurnRight()<br />

EndFor<br />

Drawing Regular Polygons<br />

You can easily change the square-drawing program (Listing 5-7) <strong>to</strong> draw<br />

other polygons. (Don’t be so square!) A polygon is just a simple closed figure.<br />

For some examples, look at the three polygons in Figure 5-11.<br />

90°<br />

60°<br />

72°<br />

Figure 5-11: The exterior angles of three polygons<br />

You use a general pattern <strong>to</strong> draw these shapes. To create the square in<br />

Figure 5-11, you draw four sides <strong>with</strong> a 90-degree turn angle after each side<br />

(that is, 360 degrees divided by 4). For the pentagon (the middle polygon),<br />

you draw five sides <strong>with</strong> a 72-degree turn angle after each side (360 divided<br />

64 Chapter 5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!