home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 December
/
simtel1292_SIMTEL_1292_Walnut_Creek.iso
/
msdos
/
pcmag
/
vol4n13.arc
/
BAR3.BAS
< prev
next >
Wrap
BASIC Source File
|
1980-01-02
|
4KB
|
91 lines
'Figure 3: (longest line = 64 characters; stat 67% in 2-column width)
0 '** Double bar chart: Program 3 **
10 INF=1.7E+38 'Infinity
20 LM=50:RM=250:TM=30:BM=140 'Screen margins
30 IF BM>190 THEN CLS:PRINT"The bottom margin is too large
for":PRINT"the titles to fit. Use a larger one.":END
40 IF TM<3 THEN CLS:PRINT"The top margin is too small
for":PRINT"the titles to fit. Use a larger one.":END
50 SCREEN 0:WIDTH 80:CLS 'Set graphics mode
60 INPUT"Number of values in vertical axis ";NV:IF NV<2 THEN 60
70 INPUT"Number of bars ";N:IF N<2 THEN 70
80 DIM S(N,2),T$(N) 'Set space for N values and titles
90 DIM M(200),N(200) 'Temporary arrays for GET and PUT
100 MAX=-INF 'Set maximum to minus infinity
110 MIN=INF 'Set minimum to infinity
120 FOR I=1 TO N
130 INPUT"Title ";T$(I)
140 FOR J=1 TO 2
150 PRINT J;
160 INPUT"Value ";S(I,J)
170 IF S(I,J)>MAX THEN MAX=S(I,J)
180 IF S(I,J)<MIN THEN MIN=S(I,J)
190 NEXT
200 NEXT
210 IF MAX=MIN THEN PRINT"All numbers are the same.":END
220 'Find longest value
230 LNG1=LEN(STR$(INT(MAX))):IF MAX>=0 THEN LNG1=LNG1-1
240 LNG2=LEN(STR$(INT(MIN))):IF MIN>=0 THEN LNG2=LNG2-1
250 IF LNG1>LNG2 THEN MAXLEN=LNG1 ELSE MAXLEN=LNG2 'Find
length of longest value
260 IF MAXLEN*8+2>LM THEN CLS:PRINT"The left margin is too small
for the":PRINT"values to fit. Use a larger one.":END
270 'Draw chart
280 SCREEN 1:CLS
290 LINE(LM,TM)-(LM,BM) 'Y-axis
300 LINE(LM,BM)-(RM,BM) 'X-axis
310 WC=(RM-LM+1)/N 'Width of one column
320 WB=WC*.8 'Width of one bar
330 MWT=WB\8 'Maximum width of titles
340 SPB=LM+WC*.5-(WB*.5) 'Starting point of first bar
350 CC=SPB+WB\2 'Center of first column
360 HW=BM-TM+1 'Height of window
370 MVP=INT(HW*.95) 'Maximum vertical point
380 FACTOR=MVP/(MAX-MIN) 'Scaling factor for bars
390 D=MAX-MIN 'Distance between MIN and MAX
400 FV=1/(NV-1) 'Factor to scale values
410 DY=MVP/(NV-1) 'Vertical distance between values
420 PY=TM+MVP-3:PX=LM-2-MAXLEN*8 'Position of values
430 'Put values in vertical axis
440 FOR I=0 TO NV-1
450 T=INT(D*FV*I+MIN) 'Value for Y axis
460 LOCATE 1,1:PRINT USING STRING$(MAXLEN,"#");T;
470 GET(0,0)-(MAXLEN*8-1,7),M 'Copy value in graphics form
480 LOCATE 1,1:PRINT SPACE$(MAXLEN);
490 DH=PY+3
500 PUT(PX,PY),M,PSET
510 FOR J=LM TO RM STEP 3 'Dotted line
520 PSET(J,DH)
530 NEXT
540 PY=PY-DY 'Set vertical position for next value
550 NEXT
560 GET(0,0)-(200,7),N 'Copy top-left part of screen
570 'Put titles in horizontal axis
580 FOR I=1 TO N
590 LOCATE 1,1:T$=LEFT$(T$(I),MWT):PRINT T$;" "
600 LT=LEN(T$)*8 'Length of title, in pixels
610 GET(0,0)-(LT,7),M 'Copy title in graphics form
620 PUT(CC-LT\2,BM+2),M 'Put title in its place
630 CC=CC+WC
640 NEXT
650 LOCATE 1,1:PRINT SPACE$(20); 'Erase last title
660 PUT(0,0),N,PSET 'Restore axis and value
670 FB=WB*.3 'Fraction of bar to make them thinner
680 'Draw bars
690 FOR I=1 TO N
700 FOR J=1 TO 2
710 HEIGHT=(S(I,J)-MIN)*FACTOR 'Height of bar
720 ON J GOTO 730,770
730 X1=SPB:Y1=MVP-HEIGHT+TM:X2=SPB+WB-FB:Y2=BM
740 LINE(X1,Y1)-(X2,Y2),1,BF
750 LINE(X1,Y1)-(X2,Y2),3,B
760 GOTO 810
770 X1=SPB+FB:Y1=MVP-HEIGHT+TM:X2=SPB+WB:Y2=BM
780 LINE(X1,Y1)-(X2,Y2),2,BF
790 LINE(X1,Y1)-(X2,Y2),3,B
800 SPB=SPB+WC 'Set position of next bar
810 NEXT
820 NEXT
830 W$=INPUT$(1)