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.

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

2. The following technique can be used to determine a good range of values for a<br />

Scale method when graphs with only positive values are to be drawn.<br />

(a) Let r be the x coordinate of the rightmost point that will be drawn by any<br />

Line, PSet, or Circle method.<br />

(b) Let h be the y coordinate of the highest point that will be drawn by any Line,<br />

PSet, or Circle method.<br />

(c) Let the numbers on the x axis range from about –[20% of r] to about r +<br />

[20% of r]. Let the numbers on the y axis range from about –[20% of h] to<br />

about h + [20% of h]. That is, use<br />

picOutput.Scale (-.2 * r, 1.2 * h)-(1.2 * r, -.2 * h)<br />

3. Usually one unit on the x axis is a different length than one unit on the y axis.<br />

The statement picBox.Circle (x, y), r draws a circle whose radius is r<br />

x-axis units.<br />

4. If one or both of the points used in the Line method fall outside the picture box,<br />

the computer only draws the portion of the line that lies in the picture box. This<br />

behavior is referred to as line clipping <strong>and</strong> is used for the Circle method also.<br />

5. A program can execute a picOutput.Scale statement more than once. Executing<br />

a new picOutput.Scale statement has no effect on the text <strong>and</strong> graphics already<br />

drawn; however, future graphics statements will use the new coordinate system.<br />

This technique can be used to produce the same graphics figure in different<br />

sizes <strong>and</strong>/or locations within the picture box. The output from the following<br />

event procedure is shown in Figure 9-8.<br />

Private Sub cmdDraw_Click()<br />

Dim i As Integer<br />

picOutput.Cls<br />

For i = 0 To 3<br />

picOutput.Scale (0, 2 ^ i)-(2 ^ i, 0)<br />

picOutput.Line (0, 0)-(.5, 1)<br />

picOutput.Line (.5, 1)-(.8, 0)<br />

picOutput.Line (.8, 0)-(0, .8)<br />

picOutput.Line (0, .8)-(1, .5)<br />

picOutput.Line (1, .5)-(0, 0)<br />

Next i<br />

End Sub<br />

FIGURE 9-8 Output from Comment 5<br />

6. The programs in this section can be modified to produce colorful displays.<br />

Lines, points, <strong>and</strong> circles can be drawn in color through use of the vbColor constants.<br />

To use color, place “, vbColor” at the end of the corresponding graphics<br />

statement. For instance, the statement<br />

picBox.Line (x1, y1)-(x2, y2), vbRed<br />

draws a red line.

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

Saved successfully!

Ooh no, something went wrong!