home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 December
/
simtel1292_SIMTEL_1292_Walnut_Creek.iso
/
msdos
/
pcmag
/
vol4n13.arc
/
BAR2.BAS
< prev
next >
Wrap
BASIC Source File
|
1980-01-02
|
3KB
|
79 lines
'Figure 2:(longest line = 64; stat 67% in 2-column width)
0 '*** Program 2 **
10 INF=1.7E+38 'Infinity
20 LM=40:RM=319:TM=3:BM=190 '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),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, Value ";T$(I),S(I)
140 IF S(I)>MAX THEN MAX=S(I)
150 IF S(I)<MIN THEN MIN=S(I)
160 NEXT
170 IF MIN=MAX THEN PRINT"All numbers are the same.":END
180 'Find longest value
190 LNG1=LEN(STR$(INT(MAX))):IF MAX>=0 THEN LNG1=LNG1-1
200 LNG2=LEN(STR$(INT(MIN))):IF MIN>=0 THEN LNG2=LNG2-1
210 IF LNG1>LNG2 THEN MAXLEN=LNG1 ELSE MAXLEN=LNG2 'Find
length of longest value
220 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
230 'Draw chart
240 SCREEN 1:CLS
250 LINE(LM,TM)-(LM,BM) 'Y-axis
260 LINE(LM,BM)-(RM,BM) 'X-axis
270 WC=(RM-LM+1)/N 'Width of one column
280 WB=WC*.8 'Width of one bar
290 MWT=WB\8 'Maximum width of titles
300 SPB=LM+WC*.5-(WB*.5) 'Starting point of first bar
310 CC=SPB+WB\2 'Center of first column
320 HW=BM-TM+1 'Height of window
330 MVP=INT(HW*.95) 'Maximum vertical point
340 FACTOR=MVP/(MAX-MIN) 'Scaling factor for bars
350 D=MAX-MIN 'Distance between MIN and MAX
360 FV=1/(NV-1) 'Factor to scale values
370 DY=MVP/(NV-1) 'Vertical distance between values
380 PY=TM+MVP-3:PX=LM-2-MAXLEN*8 'Position of values
390 'Put values in vertical axis
400 FOR I=0 TO NV-1
410 T=INT(D*FV*I+MIN) 'Value for Y axis
420 LOCATE 1,1:PRINT USING STRING$(MAXLEN,"#");T;
430 GET(0,0)-(MAXLEN*8-1,7),M 'Copy value in graphics form
440 LOCATE 1,1:PRINT SPACE$(MAXLEN);
450 DH=PY+3
460 PUT(PX,PY),M,PSET
470 FOR J=LM TO RM STEP 3 'Dotted line
480 PSET(J,DH)
490 NEXT
500 PY=PY-DY 'Set vertical position for next value
510 NEXT
520 GET(0,0)-(200,7),N 'Copy top-left part of screen
530 'Put titles in horizontal axis
540 FOR I=1 TO N
550 LOCATE 1,1:T$=LEFT$(T$(I),MWT):PRINT T$;" "
560 LT=LEN(T$)*8 'Length of title, in pixels
570 GET(0,0)-(LT,7),M 'Copy title in graphics form
580 PUT(CC-LT\2,BM+2),M 'Put title in its place
590 CC=CC+WC
600 NEXT
610 LOCATE 1,1:PRINT SPACE$(20); 'Erase last title
620 PUT(0,0),N,PSET 'Restore axis and value
630 'Draw bars
640 FOR I=1 TO N
650 HEIGHT=(S(I)-MIN)*FACTOR 'Height of bar
660 LINE(SPB,MVP-HEIGHT+TM)-(SPB+WB,BM),2,BF
670 LINE(SPB,MVP-HEIGHT+TM)-(SPB+WB,BM),3,B
680 SPB=SPB+WC 'Set position of next bar
690 NEXT
700 W$=INPUT$(1)