10 ' 20 ' Pie Graph Program ("PECANPIE/GRA") 25 ' 26 ' BASICG SAMPLE PROGRAM FOR TRS-80 MODEL II HIRES GRAPHICS BOARD 27 ' From the TRS-80 Computer Graphics Operations Manual p. 161 28 ' Minor additions by Michael Haensel 20221007 30 ' 40 ' Object 50 'The object of this program is to draw a pie graph of the 60 'expenses for a given month of eight departments of a 65 ' company, 70 ' along with the numerical value of each pie section 80 ' representation. 90 ' 100 ' 110 ' Running the program 120 'The month and the amounts spent by each department are 130 ' input, and the program takes over from there. 140 ' 150 ' Special features 160 'The amounts spent by each account as well as the total 170 'amount spent are stored in strings. The program will 180 'standardize each string so that it is 9 characters long 190 'and includes two characters to the right of the decimal 200 'point. This allows for input of variable length and an 210 'optional decimal point. 220 ' 230 'The various coordinates used in the program are found 240 ' based on the following equations: 250 ' 260 'x = r * cos(theta) 270 'y = r * sin(theta) 280 ' 290 'where x and y are the coordinates, r is the radius, 295 'and theta is the angle. 300 '(Note: The y-coordinates are always multiplied 310 'by 0.5. This is because the y pixels are twice the 315 'size of the x pixels.) 330 ' 340 'If an angle theta is generated by a percent less than 345 ' 1%, the section is not graphed, and the next theta is 350 ' calculated. 360 'However, the number will still be listed under the key. 370 ' 380 ' Variables 390 'ACCT$(i)Description of the account 400 'BUD$(i) Amount spent by the account 410 'DS$ Dollar sign (used in output) 420 'HXCOLColumn number for the pie section number 430 'HYRW Row number for the pie section number 440 ' I Counter 450 ' MN$ Month 460 ' PER(i) Percent value of BUD$(i) 470 ' R Radius of circle 480 ' T0 Angle value line to be drawn 490 ' T1 Angle value of the next line 500 ' TBUD$ Total of all the BUD$(i)'s 510 ' THALF Angle halfway between T1 and T0 (used for 520 ' location position for section number) 530 ' TILE$(i) Paint style for each section 540 ' TWOPI Two times the value of pi 550 ' X0 X-coordinate for drawing the line represented 560 ' by T0 570 ' XP X-coordinate for painting a section 580 ' Y0 Y-coordinate for drawing the line represented 590 ' by T0 600 ' YP Y-coordinate for painting a section 610 ' 620 ' Set initial values 630 ' 640 CLEAR 1000 650 DIM THALF(15),BUD$(15),ACCT$(15),PER(16) 660 TWOPI=2*3.14159 670 R=180 680 DS$="$" 690 ACCT$(1) = "Sales" 700 ACCT$(2) = "Purchasing" 710 ACCT$(3) = "R&D" 720 ACCT$(4) = "Accounting" 730 ACCT$(5) = "Construction" 740 ACCT$(5) = "Advertising" 750 ACCT$(6) = "Utilities" 760 ACCT$(7) = "Security" 770 ACCT$(8) = "Expansion" 780 TILE$(0)=CHR$(&H22)+CHR$(&H00) 790 TILE$(1)=CHR$(&HFF)+CHR$(&H00) 800 TILE$(2)=CHR$(&H99)+CHR$(&H66) 810 TILE$(3)=CHR$(&H99) 820 TILE$(4)=CHR$(&HFF) 830 TILE$(5)=CHR$(&HF0)+CHR$(&HF0)+CHR$(&H0F)+CHR$(&H0F) 840 TILE$(6)=CHR$(&H3C)+CHR$(&H3C)+CHR$(&HFF) 850 TILE$(7)=CHR$(&H03)+CHR$(&H0C)+CHR$(&H30)+CHR$(&HC0) 855 DEMO = 0 ' 1 = Normal operation, 2 = Generate random data as a demo 860 ' 870 ' Enter values to be graphed, standardize them, and calculate 880 ' the percent they represent 890 ' 900 CLS2 901 PRINT "Pecan Pie Chart Program" 902 PRINT "Do you want to:" 903 PRINT "1) Enter your own expense data for the chart?" 904 PRINT "2) See a demo chart?" 905 A$ = INKEY$ 906 IF A$ = "1" THEN DEMO = 1 ELSE IF A$ = "2" THEN DEMO = 2 ELSE 905 907 CLS2 910 PRINT @(1,0),"Enter month __________ " 920 PRINT @(3,0),"Enter amount spent by" 930 PRINT @(4,0),"$__________" 940 PRINT @(0,0),"" 950 IF DEMO = 1 THEN LINE INPUT "Enter month ";MN$ 955 IF DEMO = 2 THEN MN$ = "January" ' SAMPLE DATA 960 FOR I=1 TO 8 970 PRINT @(3,22),ACCT$(I);" " 980 PRINT @(4,0),"$__________" 990 PRINT @(3,0),"" 1000 IF DEMO = 1 THEN LINE INPUT "$";BUD$(I) 1005 IF DEMO = 2 THEN BUD$(I)=STR$(RND(10)*50) ' SAMPLE DATA 1010 IF INSTR(BUD$(I),".") = 0 THEN BUD$(I)=BUD$(I)+".00" 1020 IF LEN(BUD$(I))<9 THEN BUD$(I) = " "+BUD$(I):GOTO 1020 1030 TBUD$=STR$(VAL(TBUD$)+VAL(BUD$(I))) 1040 NEXT I 1050 IF INSTR(TBUD$,".")=0 THEN TBUD$=TBUD$+".00" 1060 IF LEN(TBUD$)<9 THEN TBUD$=" "+TBUD$:GOTO 1060 1070 FOR I=1 TO 8 1080 PER(I)=VAL(BUD$(I))/VAL(TBUD$)*100 1090 NEXT I 1100 CLS2 1110 ' 1120 ' Draw the circle and calculate the location of the lines and 1130 ' the line numbers 1140 ' 1150 CIRCLE(410,120),R 1160 FOR I=0 TO 8 1170 T0=TWOPI/100*PER(I)+T0 1180 X0=410+R*COS(T0) 1190 Y0=120-R*SIN(T0)*0.5 1200 T1=TWOPI/100*PER(I+1)+T0 1210 THALF(I)=(T0+T1)/2 1220 HXCOL=(410+R*1.15*COS(THALF(I)))*80/640 1230 HYRW=(120-R*1.15*SIN(THALF(I))*0.5)*24/240 1240 IF PER(I)>1 THEN LINE (410,120)-(X0,Y0) 1250 IF I<8 AND PER(I+1)>1 THEN PRINT @(HYRW,HXCOL),I+l 1260 NEXT I 1270 ' 1280 ' Paint the appropriate sections of the pie 1290 ' 1300 FOR I=0 TO 7 1310 XP=410+R*0.5*COS(THALF(I)) 1320 YP=120-R*0.5*SIN(THALF(I))*0 .5 1330 IF PER(I+1)>1 THEN PAINT (XP,YP),TILE$(I),1 1340 NEXT I 1350 ' 1360 ' Print the key for the graph 1370 ' 1380 PRINT @(0,0),"Expenditures for" 1390 PRINT @(1,0),MN$ 1400 PRINT @(3,0),"# Description Amount" 1410 FOR I=1 TO 8 1420 PRINT @(4+I,0),I 1430 PRINT @(4+I,4),ACCT$(I) 1440 PRINT @(4+I,15),DS$;BUD$(I) 1450 DS$=" " 1460 NEXT I 1470 PRINT STRING$(25,"_") 1480 PRINT @(14,4),"Total" 1490 PRINT @(14,16),TBUD$ 1495 PRINT @(20,0),"Press any key to continue" 1495 If INKEY$<>"" THEN 1495 ' FLUSH KEYBOARD BUFFER 1500 IF INKEY$="" THEN 1500 ` PRESS ANY KEY TO QUIT 1510 CLS2