Greyplot Dual Display Technique

Authors

Publication

Pub Details

Date

Pages

See all articles from SyncWare News v1

Here’s a way to use the grey graphics characters to plot data, much like using the PLOT (or UNPLOT) command. Since each character is a full PRINT position wide (=2 PLOT positions) the horizontal resolution is 32 (compared with 64 using PLOT). The vertical resolution though is the same, 44, The usefulness of this is that it lets you plot two different things on the same set of axes.

The effect is especially impressive when grey and white plots are made on a dark background, as in the GREYPLOT1 listing below. The display shows a unit sine wave (in grey) and its square (in white) against a black background.

The heart of the program is the subroutine at lines 40 – 80. Since it is an iterative subroutine (repeatedly used over and over) it is placed near the beginning of the instruction file to reduce the time required to run. To “plot” in grey, call the subroutine with GOSUB 40. To plot (or actually UNPLOT) in white, use GOSUB 50. Generally, when plotting in two shades, you will want to plot the grey one first, in case it gets overwritten; the effect is more pleasing to the eye when crossover points are in the stronger shade (black or white). Before calling the subroutine, load the vertical value (0 to 43, just like PLOT) into Y, and load the horizontal value (0 to 31) into H (horizontally it behaves like PRINT AT or TAB).

The program to demonstrate the routine follows. To modify it so that it prints grey and black on a white background, delete lines 110,120 and 130 and change the following lines:

40 LET L$="graphic on D
45 LET H$="graphic on S"
50 LET L$="graphic on 6"
55 LET L$="graphic on 7"

10 GOTO 100
40 LET L$="\!."
45 LET H$="\!'"
47 GOTO 60
50 LET L$="\''"
55 LET H$="\.."
60 IF Y/2-INT (Y/2)>.01 THEN LET L$=H$
70 PRINT AT 21-INT (Y/2),H;L$
80 RETURN
90 SAVE "GREYPLOT"
100 CLS
110 FOR H=0 TO 20
120 PRINT "\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::"
130 NEXT H
140 FOR H=0 TO 30
150 LET H#=CHR$(155-4*(H/5=INT(H/5)))
160 PRINT AT 10,H;H$
170 IF H<21 THEN PRINT AT H,0;H$
180 NEXT H
190 PRINT AT 0,1;"+1";AT 11,1;"0";TAB 15;"PI";TAB 29;"2PI";AT 20,1;"-1"
200 LET A$="SIN (H*PI/15)"
210 FOR H=0 TO 30
215 LET Z=VAL A$
220 LET Y=22+INT (20*Z+.5)
230 GOSUB 40
240 LET Y=22+INT (20*Z*Z+.5)
250 GOSUB 50
290 NEXT H

When you ran GREYPLOT1, you may have noticed that at two points, just before and after the first peak, a grey spot is plotted and then erased by the white (or black) spot, even though the new spot is in the next lower position. This is because when printing the second character, it is in the same PRINT position as the grey character. We can PEEK the appropriate location in the display file to find out if there is already a half-grey character there, and if so make the appropriate correction to L$ before we print it (or rather POKE – since we already have the location in L, why not?)

Greyplot2

Make the following changes to the GREYPLOT1 listing:

5 LET DF=PEEK 16396+256*PEEK 16397
62 LET L=DF+33*(21-INT (Y/2))+H+1
65 IF PEEK L=138 AND L$="gr.7" THEN LET L$="gr.S"
67 IF PEEK L=137 AND L$="gr.6" THEN LET L$="gr.D"
70 POKE L,CODE L$

Now all is as it should be, and the white spot doesn’t wipe out any grey ones in the next place. One warning – when using this method of addressing the display file, be sure to execute the line that looks up the display file start (5 in this case) after making program changes. Otherwise you’ll POKE some wrong things, with resulting goofy behavior or crashes, Also, when using a machine with RAMTOP at 3.25K or less (as with a 2K machine) be sure to pad out the display file first; e.g. for a white background.

110 FOR H=0 TO 21
120 PRINT AT H,31;" "
130 NEXT A

Unless you’re certain that the data won’t exceed the limits of H and Y, as in the example, you should include traps in case out-of-range numbers are sent into the subroutine. Example: 61 IF H>31 OR H43 OR Y<0 THEN RETURN would do the trick. Otherwise, the POKE will change values in the program or variables area instead!

TRIPLOT

If we take all this to extremes, we might come up with something like the following listing. A sine wave is plotted in grey, and a decaying exponential in small black spots, Their product, a damped sinusoid, is shown with large black spots. The PLOT command in line 270 wipes out adjacent grey spots, much like GREYPLOT1 did. Can you work out a way around this?

5 LET DF=PEEK 16396+256* PEEK 16397
10 GOTO 100
40 LET L$=" "
45 LET H$="\!:"
47 GOTO 60
50 LET L$="\.."
55 LET H$="\''"
60 IF Y/2-INT (Y/2)>.01 THEN LET L$=H$
62 LET L=DF+33*(21-INT (Y/2))+H+1
65 IF PEEK L=10 AND L$="\.." THEN LET L$="\!'"
67 IF PEEK L=9 AND L$="\''" THEN LET L$="\!."
70 POKE L,CODE L$
80 RETURN
90 SAVE "TRIPLOT"
95 RUN
100 CLS
110 FOR H=0 TO 21
120 PRINT AT H,31;" "
130 NEXT H
140 FOR H=0 TO 30
150 LET H$=CHR$ (27-4*(H/5=INT(H/5)))
160 PRINT AT 10,H;H$
170 IF H<21 THEN PRINT AT H,0;H$
180 NEXT H
190 PRINT AT 0,1;"+1";AT 11,1;"0";TAB 15;"PI";TAB 29;"2PI";AT 20,1;"-1"
200 LET A$="SIN (H*PI/10)"
205 LET B$="EXP (-H/15)"
210 FOR H=0 TO 30
215 LET Z1=VAL A$
216 LET Z2=VAL B$
220 LET Y=22+INT (20*Z1+.5)
230 GOSUB 40
239 LET Y=22+INT (20*Z1*Z1+.5)
250 GOSUB 50
260 LET Y=22+INT (20*Z2+.5)
270 PLOT 2*H,Y
290 NEXT H

Products

 

Downloadable Media

 
Scroll to Top