12.07.2015 Views

williams-et-al-1983-apple-ii-computer-graphics

williams-et-al-1983-apple-ii-computer-graphics

williams-et-al-1983-apple-ii-computer-graphics

SHOW MORE
SHOW LESS
  • No tags were found...

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

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

CHAPTER 11-GRAPHS AND CHARTS 13 1After you have run the program a few times with your own data, we cango through it and hit the highlights.7¥' DEF FN X (T) =8Y, DEF FN Y(T) =8Y, * COS (T)7Y, * SIN (T)The fu nctions defi ned here are used to c<strong>al</strong>culate the X and Y-coordinatesof points on the circle. The v<strong>al</strong>ues 80 and 70 define the radius of the circle(two rad<strong>ii</strong>?!?). The dots on the screen are slightly higher than they are wide,so if you l<strong>et</strong> both numbers be 80 (as theor<strong>et</strong>ic<strong>al</strong>ly they should), the pielooks more like an egg.12¥' READ NUM%13¥' DIM DTA( NUM%)14Y, FOR . I = 1 TO NUM%15¥' READ DTA(I)16Y, TTL = TTL + DTA( I)17¥' NEXT INUM% is the number of regions, and the data v<strong>al</strong>ues are read into the arrayDTA. Since a tot<strong>al</strong> is required to c<strong>al</strong>culate the relative size of each "slice,"we accumulate the data v<strong>al</strong>ues in TTL.24¥' FOR T = Y, TO 1. 57 STEP • Y,125¥' X = FN X(T) :Y = FN Y(T)26Y, HPLOT X + 14Y,, Y + ' 8y,27¥' HPLOT -X + 14Y,, Y + 8Y,28¥' HPLOT X + 14¥', -Y + 8Y,29¥' HPLOT -X + 14Y,, -Y + 8Y,3¥'¥' NEXT TThe circle is drawn using a little simple trigonom<strong>et</strong>ry. (There is re<strong>al</strong>ly nosuch thing as simple trigonom<strong>et</strong>ry!) You will notice here (and <strong>al</strong>so later inthe program) that we place the center at (140,80) by adding 140 to each Xand 80 to each Y as we plot.The re<strong>al</strong> question is, why does T go from 0 to 1.57? The SIN and COSfunctions we use measure a circle in radians instead of degrees. There areroughly 6.28 radians in a fu ll circle (3.14 in a semicircle), and we use thesymm<strong>et</strong>ry of the circle so that we only need to c<strong>al</strong>culate the points for onequarterof the circle. The result of <strong>al</strong>l this is that we go one-quarter of theway to 6.28, and one-quarter of 6.28 is the elusive 1.57.36Y, FOR I = 1 TO NUM%37¥' ACC = ACC + DTA(I)38¥' R = (ACC / TTL) * 6.2839¥' HPLOT 14Y,, 8Y, TO FN X (R) + 14Y,,FN Y(R) + 8¥'4Y,Y, NEXT I41Y, END

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

Saved successfully!

Ooh no, something went wrong!