19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

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

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

278 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

FIGURE 9-18 (a) Arc of a Circle <strong>and</strong> (b) Sector of a Circle<br />

A special case occurs when a is 0. The expression –a * c will be zero rather than a negative<br />

number. As a result, <strong>Visual</strong> <strong>Basic</strong> does not draw the horizontal radius line associated<br />

with a = 0. In order to create a sector that has the horizontal radius line as one of its edges,<br />

use a small number such as .0000001 for a.<br />

EXAMPLE 2<br />

Write a program to draw a sector whose sides are a horizontal radius line <strong>and</strong> the radius line that is 40<br />

percent of the way around the circle.<br />

SOLUTION:<br />

The following program draws the sector with its center at the center of the picture box. The radius was<br />

arbitrarily chosen to be 2 <strong>and</strong> the picOutput.Scale statement was chosen so that the circle would be fairly<br />

large. The output displayed in the picture box is shown in Figure 9-19.<br />

Private Sub cmdDraw_Click()<br />

Dim c As Single<br />

picOutput.Cls<br />

picOutput.Scale (-3, 3)-(3, -3) ‘Specify coordinate system<br />

c = 2 * 3.14159<br />

a = .0000001<br />

b = .4<br />

‘Draw sector with radius lines corresponding to 0 <strong>and</strong> .4<br />

picOutput.Circle (0, 0), 2, , -a * c, -b * c<br />

End Sub<br />

FIGURE 9-19 Display from Example 2<br />

A sector can be “painted” using any of the patterns shown in Figure 9-20. Which pattern<br />

is used to fill a sector is determined by the value of the FillStyle property. The default value<br />

of this property is 1 for transparent. Thus, by default, the interior of a sector is not painted.<br />

FIGURE 9-20 Fill Patterns

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

Saved successfully!

Ooh no, something went wrong!