--------------------------------------- 3]AMIGA BASIC TUTORIAL, PARTS 4-6 3]By Jonathan Potter, Clarence, Australia --------------------------------------- (EDITOR'S NOTE: This series began last month and will continue. It is aimed less at the beginning programmer than the programmer who may know the fundamentals of Basic but is new to Amiga Basic. The series resumes with a look at graphics.) 3]DRAWING FUNCTIONS All of the Amiga Basic drawing functions take the form: (x,y) or (x1,y1)-(x2,y2) . . . and a brief rundown of them follows. CIRCLE [STEP] (x,y),radius [,color id [,start,end[,aspect]]] (x,y) are the coordinates for the origin of the circle. is the radius in pixels. is the drawing color. and refer to the start and end angles in radians, and range from -2pi to 2pi. These angles allow the user to specify where an ellipse starts and ends. If or are negative, the circle is connected to the origin with a line, and the angles treated as positives. is the ratio of the width to height of one pixel (eg, the aspect ratio of an 1081 monitor is 2.25:1, so the would be 1/2.25, which is .44. This is the default). The [STEP] option is present in most drawing commands, and indicates the x and y coordinates are relative to the current, or most recently referenced coordinates of the pen. If the last referenced point was (10,10), the command CIRCLE STEP (20,15),10 would draw a circle with origin (30,25) and radius 10. 3]EXAMPLES CIRCLE (100,100),100 - Circle with radius 100, origin (100,100) CIRCLE (300,30),50,4,,,.5 - Circle with radius 50, origin (300,30), color 4, with aspect ratio of .5 (pixels twice high as wide.) CIRCLE (300,100),100,,1.5,4.5 - Circle with radius 100, origin (300,100), starting at 1.5 rads, and ending at 4.5 rads. LINE [[STEP](x1,y1)-[STEP](x2,y2),[color-id] [,b[f]] (x1,y1) are the starting coordinates for the line. As in circle, STEP indicates to the pen position. (x2,y2) are the ending coordinates for the line. This time, STEP refers to the (x1,y1) coordinates. is the drawing color. The b parameter makes a box be drawn instead of a line. In this case, (x1,y1) are the upper-left coordinates, and (x2,y2) the lower-right. The bf parameter causes the box to be filled in. EXAMPLES LINE (10,10)-(100,100),3 - Draws a line from (10,10) to (100, 100) in color 3. LINE (100,100)-(150,120),,bf - Draws a filled in box with upper-left coordinates (100,100) and lower right coordinates (150,120). LINE STEP (10,10)- STEP (30,50),,b - Draws a box with upper-left coordinates (10,10) from last referenced position, and lower- right coordinates (30,50) from (10,10) the first coordinates. PAINT [STEP](x,y)[,paintColor-id [,borderColor-id]] (x,y) are the coordinates of any point within the area to be painted (filled). STEP again refers to a relative point. is the color that the area is to be painted. is the color of the border surrounding the to-be-painted area (the color at which filling stops.) If this value is not specified, is used. EXAMPLES PAINT (100,100),5,3 - Fills in an area with an interior point (100,100), with color 5, stopping at color 3. PAINT (50,300),2 - Fills an area with interior point (50,300) with color 2, not stopping until color 2 is found. 3]BASIC TUTORIAL PART 5 PALETTE ,,, PALETTE allows you to set the color registers for your program. is the color register, a value from 0 to 31.(0 is the background color). , and are values from 0.00 to 1.00, indicating a decimal percentage of red, green and blue. Combined, these parameters define a color. EXAMPLES PALETTE 0,1,1,1 - sets the background color to white. PALETTE 1,1,.6,0 - sets register 1 to orange. PALETTE 18,.8,0,.93 - sets register 18 to purple. POINT (x,y) POINT returns the color id of the point at (x,y) EXAMPLES PRINT POINT (100,100) - Prints the color id at the point (100,100). IF POINT(300,10)=0 THEN main - Goes to main: if the point at (300,10) is blank. 0 is the default background color. PSET [STEP] (x,y) [,] PSET sets a point (x,y) in the current output window to the current foreground color. Default is color ID 1 if none is specified. Otherwise, to the color specified by . As with other commands, STEP specifies a location relative to the last referenced point, rather than an absolute point. EXAMPLES PSET (100,100),3 - Sets point at (100,100) to color 3. PSET STEP (300,-10) - sets point 300 pixels to the left, and 10 pixels up from the last referenced point to the current foreground color. PRESET [STEP] (x,y) [,] PRESET is identical to PSET in every way except one: If is omitted, the point is set to the current background color, rather than the foreground. EXAMPLES PRESET (100,100),3 - Does exactly the same thing as the first example for PSET. PRESET STEP (300,-10) - Sets point 300 pixels to the left, and 10 pixels up from the last referenced point (as did the second example for PSET) but in the background color rather than the foreground color. AREA [STEP] (x,y) AREA defines a point of a polygon to be acted upon by AREAFILL. The (x,y) parameters specify one of up to 20 points that form a polygon. If STEP is specified, (x,y) are relative from the last AREA (x,y) parameters. AREA is reset after AREAFILL has been executed, so if you wish to AREAFILL the same polygon again, you must redefine it with AREA. EXAMPLES AREA (10,10):AREA (100,10):AREA (100,50): AREA(10,50) - Defines a square with corners at (10,10), (100,10), (100,50) and (10,50). AREA (100,10):AREA STEP (50,0):AREA STEP (0,50): AREA STEP (-50,0) - Defines a square with sides of 50. Its corners are at (100,10), (150,10), (150,60) and (100,60). AREAFILL [mode] AREAFILL alters the interior of the polygon defined by AREA statements. The [mode] parameter is either 0 or 1. 0 - fills the area with the area pattern established by a PATTERN command. 1 - inverts (reverses colors in the) the area. 0 is the default parameter. If no [mode] is specified, the pattern defined by PATTERN will be used. EXAMPLES AREAFILL 1 - Inverts (reverses) the colors in a defined area. This, for example, generates the same effect as clicking with the left mouse button and holding on a Boolean type gadget, such as the CANCEL of a system request. AREAFILL 0 - this will fill in the defined area with the pattern specified by PATTERN. PATTERN [][,] PATTERN allows textured fills of polygons, and lines and text. is a hexadecimal number that defines a 16 bit value to be used for line drawing. is the name of an integer array containing the pattern. The array defines a 16 bit wide by 2^n high value to be used for AREAFILL 0 where n is any integer from 1 to 5 inclusive. The array contains 2^n elements. Determining the 16 bit and 16X2^n bit values is somewhat reminiscent of designing sprites on the C-64. Each 16 bit long line (only one in the ) consists of on and off pixels. e.g for a dotted line effect the binary value would be 1010101010101010. This must then be converted to a hex value which in this case is &HAAAA (each of the four groups of four bits (1010) yields in this case a decimal 10, which is A in hex.) If the command PATTERN &HAAAA was executed, subsequent lines and text drawn would be dotted (on/off/on/off....). This would continue until a solid was defined (1111111111111111) which is hex &HFFFF. (e.g PATTERN &HFFFF). If for example you defined an array as pat%, like this: DIM pat%(1) pat%(0)=&HAAAA(&HAAAA is 1010101010101010) pat%(1)=&H5555(&H5555 is 0101010101010101) . . . and then executed the command: PATTERN ,pat% . . . any subsequent AREAFILL 0 commands would fill the area with the pattern defined in array pat%, in this case, a dotted pattern. This would continue until . . . DIM pat%(1) pat%(0)=&HFFFF pat%(1)=&HFFFF PATTERN ,pat% . . . was executed, resetting the fill pattern to solid. BASIC TUTORIAL PART 6 GET (,)-(,),[(index list] GET has two functions - a graphical function (described below), and an I/O function (which will be described in later tutorials). GET is used in conjunction with PUT (see below) to transfer graphic images from one part of the screen to another. (,) and (,) are the top left and bottom right corners respectively of the rectangle you wish to GET. is the name of the array that will hold the image. The array can be any type except a string, but the contents of the array will be meaningless when directly interpreted, unless the array is an integer (as in array%). The required dimension of the array is calculated by the following formula: (6+((y+1)*2*INT((x+16)/16)*D)/BYTES . . . where x and y are the lengths of the horizontal and vertical sides of the rectangle (x and y can be calculated like so: x=x2-x1 and y=y2-y1), and D is the screen depth, for which 2 is the default. For coverage of depth, see the May 1989 JUMPDISK's tutorials in this series. integer - 2 bytes single precision - 4 bytes double precision - 8 bytes Therefore, if you wished to . . . GET (10,20)-(30,40),ARRAY% . . . from the normal Workbench screen (depth of 2), the number of elements required for ARRAY% is . . . (6+((20+1)*2*(INT((20)+16)/16))*2)/2 . . . which works out to 87 elements. So you would have to DIM ARRAY%(87). The allows you to define multiple images in a multi-dimensional array. PUT [STEP] (,), [(index-list)] [action-verb] PUT, like GET, has a graphical and an I/O function. The I/O function will be discussed in future tutorials. PUT is used to place an image defined by GET from the array on the screen, with top left coordinates (,). The allows mutiple images in a multi-dimensional array. STEP again refers to a point relative from the last referenced point, rather than an absolute point. is one of PSET, PRESET, AND, OR or XOR, and defines how the placement will interact with the screen. PSET will place the image on the screen, totally obscuring anything underneath it. PRESET will do the same as PSET, but will invert (reverse) the colors. AND will perform a logical And on the image and what is already on the screen, and display the result. OR will perform a logical Or on the image and what is already on the screen, and display the result. XOR (which is the default) will place the image over the whatever is already on the screen, but will let what is there show through. EXAMPLES PUT (20,90),ARRAY%,PSET - Places the image from ARRAY% on the screen at (20,90), obscuring what is already there. PUT STEP (10,10),ARRAY% - Places the image from ARRAY% on the screen (10,10) from the last referenced point. COLOR [] [,] COLOR allows you to set the current foreground and background drawing colors. is a value from 0 to 31, which corresponds to a color register set by the PALETTE command. is a value from 0 to 31, which corresponds to a color register set by the PALETTE command. All graphics and text will be drawn in the current foreground color, unless specified otherwise. EXAMPLES COLOR 1,0 - This is the default color setup, which with the default system colors produces white text on a blue background. COLOR 0,1 - With the default system colors, this produces blue text on a white background. COLOR 3,2 - Foreground color 3, background color 2 COLOR 8 - Foreground color 8, background color unchanged. COLOR ,9 - Foreground color unchanged, background color 9. WINDOW CLOSE WINDOW OUTPUT SCREEN CLOSE WINDOW These four commands were inadvertently left out of previous tutorials. Briefly, WINDOW CLOSE will close a window once it has been opened. is the id of the window. WINDOW OUTPUT will direct all screen output (text, graphics, etc.) to the window . Default for this is 1, the default Amiga Basic output window. SCREEN CLOSE will close a screen once it has been opened. is the id of the screen. WINDOW will return information about the status and size of the current output window. is any number from 0 to 8. value Information returned 0 The window-id of the selected output window. 1 The window-id of the current output window. 2 The width of the current output window. 3 The height of the current output window. 4 The x coordinate in the current output window where the next character is drawn. 5 The y coordinate in the current output window where the next character is drawn. 6 The maximum legal color for the current output window. 7 A pointer to the INTUITION WINDOW record for the current output window. 8 A pointer to the RASTPORT record for the current output window. These last two are not necessary for the casual programmer. However, if you require information about them, see the manual "Intuition: The Amiga User Interface." EXAMPLES WINDOW CLOSE 1 - Will close window 1. When Amiga Basic is first started this is the output window. WINDOW OUTPUT 3 - Will direct screen output to window 3. SCREEN CLOSE 2 - Closes screen 2. PRINT WINDOW(2)*WINDOW(3) -Returns the area in pixels of the current output window. 3]END OF TEXT