94 APPLE II COMPUTER GRAPHICS50 HGR60 FOR Cl = 1 TO 770 FOH C2 = 1 TO 780 FOR Y = 0 TO SZ STEP 290 HCOLOR = Cl100 HPLOT 0 ,Y TO SZ,Y110 HCOLOR = C2120 HPLOT 0, Y + 1 TO SZ , Y + 1130 NEXT Y140 FOR I = 1 TO DLAY : NEXT I150 NEXT C2160 NEXT Cl170 ENDListing 9-4. Dithering.You should see a rectangle in the upper left corner of the screen whichcontinu<strong>al</strong>ly changes color, and in the process takes on some shades otherthan the basic six. You may change the speed by <strong>al</strong>tering the v<strong>al</strong>ue ofOLAY in line 30, and the size of the rectangle is d<strong>et</strong>ermi ned by the v<strong>al</strong>ueof SZ in line 40.All the program does is plot pairs of horizont<strong>al</strong> lines in two <strong>al</strong>ternatingcolors (C1 and C2), then change one or both colors and do it again. As theroutine cycles, you can see the basic colors-green, blue, viol<strong>et</strong>, orange,black, and white-but <strong>al</strong>so some other colors such as light green and hotpink. The extra colors are generated by two colors blurring tog<strong>et</strong>her toform a mixture, for instance white and green blurring to form light green.There are a great many variations used to produce other shades. Forexample, you might mix the colors orange and black, by <strong>al</strong>ternating themin a checkerboard pattern to produce dark orange, or perhaps by drawinga pure orange line fo llowed by a line which <strong>al</strong>ternates orange and black.The possibil ities are limited only by your imagination.There are a few considerations, however. For instance, if you tried to<strong>al</strong>ternate green and viol<strong>et</strong> dots across the screen, as in the following shortprogram, you would run into severe problems.10 HGR20 Cl = 2: C2 = 130 FOR X = 0 TO 278 STEP 240 HCOLOR = Cl : HPLOT X , Y: REM VIOLET50 GOSUB 10060 HCOLOR = C2 : HPLOT X + 1, Y: REM GREEN70 GOSUB 10080 NEXT X90 END100 FOR I 1 TO 200 : NEXT I: RETURNListing 9-5.
CHAPTER 9-Hl-RES COLOR 95Thanks to the delay loop in line 1©©, you will be able to see <strong>al</strong>l theaction when the program runs. The fi rst dot appears in its proper viol<strong>et</strong>,but then the next dot comes on- not as the expected green, but as white,and the first dot turns white with it. The remaining dots <strong>al</strong>so display white,regardless of the color s<strong>et</strong> in the program. Remember, any time two consecutivedots in a row are on, they display white, so if you wish to <strong>al</strong>ternatecolors across a line, you must leave one or more black dots b<strong>et</strong>weeneach color and the next (see Figure 9-5).m 1 m 1 m 1 mFigure 9-5. Alternating colors.Even if you leave black dots b<strong>et</strong>ween colored dots, you are still notcompl<strong>et</strong>ely safe. The next listing ostensibly plots viol<strong>et</strong> in col umn ©, blue incolumn 2, viol<strong>et</strong> in column 4, blue again in column 6, and so on acrossthe line.l HGR2 Cl = 2:C2 = 63 FOR X = TO 276 STEP 44 HCOLOR = Cl : HP LOT X , Y: REM VIOLET5 GOSUB l6 HCOLOR = C2 : HP LOT X + 2, Y: REM BLUE7 GOSUB l8 NEXT X9 ENDl FOR I = 1 TO 2 : NEXT I : RETURNListing 9-6.When the program runs, a viol<strong>et</strong> (group 1) dot will appear in column ©,then a blue dot will appear in column 2. Since blue is in group 2, theentire byte will become group 2 and the viol<strong>et</strong> dot will change to blue<strong>al</strong>so. Next, a viol<strong>et</strong> dot will be plotted in column 4, turning the previoustwo dots viol<strong>et</strong>, and then a blue dot will be plotted in column 6 to turneverything blue again. Column 8 is in the next byte of memory so whenthe viol<strong>et</strong> dot is plotted there, the previous four dots are unaffected.Column 1 © displays blue, and then column 12 displays viol<strong>et</strong> so that th<strong>et</strong>hree dots in that byte are <strong>al</strong>l viol<strong>et</strong>. Column 14 begins the third byte, and,as it displays blue, the previous three dots remain viol<strong>et</strong>. The fi n<strong>al</strong> patternis a line which has <strong>al</strong>ternating viol<strong>et</strong> and blue segments.This demonstrates a propensity of Hi-Res <strong>graphics</strong> c<strong>al</strong>led "clashing."Clashing is the inadvertent switching of a dot from one color group to theother and occu rs when you attempt to plot colors from opposite colorgroups within the same byte-the <strong>computer</strong> simply cannot and will not doit-so the attempt turns the first colors plotted into colors from the secondgroup plotted. You cannot mix green with orange or blue in the samebyte, nor can you put orange or blue in the same byte as viol<strong>et</strong>. Clashing is