/-------------------------------------------------------------------------\
|                                                                         |
| The ALLIANCE presents : Amiga Graphics Inside and Out from Abacus.      |
|                                                                         |
| This is the second in our series of complete books and due to the sheer |
| size of this one will be spread across the next 2 or 3 of our docs      |
| disks.                                                                  |
|                                                                         |
| Typed By RAZOR BLADE and ASTERIX of Alliance.                           |
|                                                                         |
| Greets to the rest of Alliance :                                        |
|                                                                         |
| Alchemist                                                               |
|   Chaos                                                                 |
|     Mit                                                                 |
|       Shadowfax                                                         |
|         Viper                                                           |
|                                                                         |
\_________________________________________________________________________/

---------------------------------------------------------------------------
ABACUS						      1.5  MEDLEY OF COLORS

The Amiga provides a palette of 4096 colors. If you use pure BASIC you can
only use 32 colors at a time (we'll show you how to use more later). The
specific colors are stored in the color registers. When you use a
statement, you are not selecting which color to use but which color
register to get the color from.

You cannot use all 32 colors in any type of screen. The number of possible
colors depends on the depth of your screen. A normal Workbench screen has a
depth of two, which allows you four colors. For every pixel there are two
bits in memory which determine those four colors. 

	00	Color register 0
	01	Color register 1
	10	Color register 2
	11	Color register 3

To display 32 colors you need five bits per pixel, but first you have to
open a new screen with a depth of five:

	SCREEN 1,320,200,5,1
	WINDOW 2,"TITLE",(0,0)-(311,185),16,1

Now you could use all the statements you have learned so far with 32
colors.

Of the 32 colors available, you can select one for the foreground and one
for the background.

	COLOR 1,0

These are the two default values. The first sets the foreground color and
the second sets the background color. All the graphic statements will use
these two colors. As longs as you leave the color parameter off, even PSET
will use the default foreground color, and PRESET will use the default
background color.

Changing the foreground and/or background, color does not instantly change
the screen colors. Using the CLS statement makes the new colors take
effect.

                                 PAGE 41

---------------------------------------------------------------------------
AMIGA GRAPHICS				      AMIGA GRAPHICS IMSIDE AND OUT

	COLOR 2,3
	CLS

The above statement gives you an orange screen with a black foreground
color. 

		----------------------------------------
1.5.1			  THE COMPLETE PALETTE


Most of the time you will probably want a completely different set of
colors in you program instead of the 32 default colors. To do this, you
have to change the colors in the color registers.

Every color is composed of three values which set the read, green and blue
of the color(RGB). Each of these values has a range from one to 4096.

The BASIC statement use to change the colors is PALETTE. You must specify
the RGB(red, green and blue) values and which color register to change. The
RGB color division must be a number between zero and one.

	PALETTE 0,.75,1,0

This line sets a neon yellow background. This color is a mix of red and
yellow, blue is not used. To set the normal blue background:

	PALETTE 0,0,.3,.6

Setting the red to one(1) and the other ranges to zero gives you red. This
procedure works the same for the other two ranges.

		----------------------------------------

1.5.2		 	 CHANGING RGB COLORS

You can find any color you want by experimenting with the three color
ranges. However, finding a specific color with this method could be tiring.
The following program allows you to search for and find your target color.
You can change all three ranges while the program is running and quickly

                               PAGE 42

----------------------------------------------------------------------------
ABACUS							1.5 MEDLEY OF COLORS

find your desired combination. The results are visible on the screen at the
same time.

	REM 1.5.2 ColorConstructor
	SCREEN 1,320,200,2,1
	WINDOW 2,"ColorConstructor",(0,0)-(297,185),31,1
	LINE (200,20)-(300,150),3,bf
	LOCATE 5
	PRINT "> '4'   '5'   '6'"
	LOCATE 16
	PRINT "< '1'   '2'   '3'"
	LOCATE 10
	PRINT "   R   G   B"
	r=1:g=.5:b=0	' orange
	WHILE 1
	LOCATE 11
	PRINT USING "  #.##";r;g;b
	PALETTE 3,r,g,b
	WHILE A$=""
	 A$=INKEY$
	WEND
	 IF A$<>"" THEN
	  IF A$="1" and r>=.0666 THEN r=r-.06666			
	  IF A$="4" and r>=.9333 THEN r=r+.06666			
	  IF A$="2" and g>=.0666 THEN g=g-.06666			
	  IF A$="5" and g>=.9333 THEN g=g+.06666			
	  IF A$="3" and b>=.0666 THEN b=b-.06666			
	  IF A$="6" and b>=.9333 THEN b=b+.06666			
	 END IF
	WEND

You can change the color ranges by using the 1-6 keys. The numeric keypad
is perfectly arranged for changing color ranges. The 4 key raises and the 1
key lowers it. The 5 and 2 keys raise and lower the green range, and the 6
and 3 keys raise and lower the blue range.

The color range will increase and decrease by a value of 0.0666 or 1/15.
This insures a color range with every keypress.

You can also change the mouse pointer colors with the PALETTE. The effected
registers are 17,18 and 19. Try it out.

		----------------------------------------
1.5.3			THE OPPOSITE OF PALLETTE

In many programs it is very important to know what colors are in the
palette. However, there is no statement in BASIC that performs the opposite
of PALETTE. Again we will step ahead a little and get out our data directly

			         PAGE 43

----------------------------------------------------------------------------
AMIGA GRAPHICS  			       AMIGA GRAPHICS INSIDE AND OUT

from memory. We will explain later, when we leave pure BASIC, how to
detemine the address of the color table. 

Since the functions assigned at the beginning of the program take care of
any addresses or PEEKs, you do not have to concern yourslef with these. You
just have to provide the color register number to the function. There are
three functions, one for each RGB color range.
	
	REM 1.5.3 Palette-Opposite
	SCREEN 1,320,200,5,1
	WINDOW 2,,,16,1
	DEF FNcolortab=PEEKL(PEEKL(PEEKL(WINDOW(7)+46)+48)+4)
	DEF FNred(f)=(PEEKW(FNcolortab+2*f) AND 3840)/3840
	DEF FNgreen(f)=(PEEKW(FNcolortab+2*f) AND 240)/240
	DEF FNblue(f)=(PEEKW(FNcolortab+2*f) AND 15)/15
	PRINT "RGB Color Values:"
	FOR i = - TO 31
	  LOCATE 5+i MOD 16,1+INT(i/16)*20
  	  COLOR i
	  PRINT USING "##";i,
  	  COLOR 1
	  PRINT USING " #.##";FNred(i);FNgreen(i);FNblue(i)
	NEXT i
	WHILE INKEY$="":WEND
	WINDOW CLOSE 2
	SCREEN CLOSE 1

This program prints out the color values for evry color. The color register
and color are listed in front of the three ranges.

		----------------------------------------
1.5.4			ANIMATION USING COLOR

Now we'll show you away to make functions from the last program useful. You
can easily animate a picture by repeatedly swapping several colors. This
color cycling trick may be familier to you because paint programs, such as
GraphiCraft and Deluxe Paint, use it. You can magically display moving
rivers or similar actions with this method. With some porgramming, this
color swapping is possible in BASIC. However, you should keep the number of
colors being swapped as small as possible because of BASIC's slowness. If
you use too many colors, the cycling will be slower, causing a jerky and
ragged look. 

	REM 1.5.4 Palette-Opposite Expanded
	SCREEN 1,320,200,5,1
	WINDOW 2,,,16,1
	PALETTE 0,0,.5,0
	PALETTE 28,0,.35,.72

				PAGE 44

----------------------------------------------------------------------------
ABACUS							1.5 MEDLEY OF COLORS

	PALETTE 29,0,.35,1
	PALETTE 30,0,.5,1
	PALETTE 31,0,.6,1
	DEF FNcolortab(PEEKL(PEEKL(WINDOW(7)+46)+48+4)
	DEF FNred(f)=(PEEKW(FNcolortab+2*f) AND 3840)/3840
	DEF FNgreen(f)=(PEEKW(FNcolortab+2*f) AND 240)/240
	DEF FNblue(f)=(PEEKW(FNcolortab+2*f) AND 15)/15
	f1=28:f2=31
	FOR j=0 TO 311 STEP 4
	FOR i=0 to 3 STEP .5
	  LINE (j+i,120+j/8)-(J+i-4,140+j/8),28+i
	  LINE (j+i+1,120+j/8)-(J+i-3,140+j/8),28+i
	
	NEXT i
	NEXT j
	rotation:
	r1=FNred(f2)-.03
	g1=FNgreen(f2)-.03
	b1=FNblue(f2)-.03
	FOR i=f1 TO f2
	  r=FNred(i)-.03
	  g=FNgreen(i)-.03
	  b=FNblue(i)-.03
	  PALETTE i,r1,g1,b1
	  r1=r
	  g1=g		
  	  b1=b
	NEXT i
	GOTO rotation

This program draws an abstract river. We set the last eight color registers
to blue for the river.

In the program routine "rotation" we subtract .03 from the recieved color
range before using the value with PALETTE. This corrects a calculation
error for the floating point value, that is between 0 and 15, which we
received from memory.

				PAGE 45

----------------------------------------------------------------------------



