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