GRAPHICS A graphic is anything that has been drawn and appears on the screen. The monitor screen is composed of a large number of small rectangles called pixels, which are like the dots on a TV screen. The default screen is 640X256 pixels, but because on boundaries etc. in AMIGAbasic you can only use an area within 617X240 pixels. Note that these dimensions apply to the PAL screen, the NTCS screen is 640x200 pixels. (PAL is the Australian standard while NTCS is the US standard.) If you create a window, or create graphics outside this area, you will get an ILLEGAL FUNCTION CALL message. Each pixel is a rectangle whose height is twice as high as its width. A character on the screen occuppies a rectangle of 8x8 pixels. The grid location of a pixel can be given to variables. A horizontal distance is twice the number of pixels as the vertical distance. This section includes some statements which applies to screens and graphics. q 11001 QUIZ ON GRAPHICS Type 1 for true, 0 for false (1) Text is included as graphics (2) Pixels are twice as high as they are wide (3) Pixels are square (4) A character is 10x10 pixels (5) Boundaries of windows reduce available windows CLS Clears the entire window and moves the cursor to the top left hand corner. If there are no custom windows the entire screen will be cleared. Using this may prevent the user from seeing what was displayed on the screen window immediately prior. This could be avoided by e.g. placing an input statement before using CLS. q 10011 QUIZ ON CLS Type 1 for true, 0 for false (1) CLS places the cursor in the top left corner (2) CLS removes everything from the screen (3) CLS keeps the cursor at the current position (4) CLS happens immediately (5) CLS removes everything from the current window LOCATE Locate x,y moves the cursor to where x=column number,y=row number. Any variables or constants can be used instead of x and y. Standard screen has 23 rows and 60 columns. Columns go from left to right. Rows go from top to bottom. This follows standard reading procedure. Locate statements can be used in loops to create interesting effects. e.g.LOCATE 10,5 e.g.LOCATE row,col CSRLIN (CurSoR LINe) Gives the current row of the cursor. e.g. x=CSRLIN ,x will equal the current row POS(x) (POSition x) Gives the current column of the cursor. e.g. y=pos(x), y will equal the current column Using these statements together will give the location of the cursor. These can be used in conjunction with locate to create loops etc. q 11001 QUIZ ON CURSOR POSITION Type 1 for true, 0 for false (1) CSRLIN means the row the cursor is in (2) CSRLIN and POS(x) can be used to find the current cursor position (3) LOCATE cannot use variables for rows or columns (4) LOCATE positions the cursor within a certain number of pixels (5) PTAB moves the cursor the given number of rows PTAB (PixelTAB) You can use this to locate the cursor within the current line. X is the number of pixels rather than characters. e.g. ptab(50);"fred" prints "fred" 50 pixels along from the left This means that a character need not be placed exactly in a row. q 01100 QUIZ ON PTAB Type 1 for true, 0 for false (1) PTAB places the cursor at a certain column (2) PTAB places the cursor a certain number of pixels across (3) A variable or constant can be used (4) PTAB places the cursor within the current column (5) A character must be placed exactly in a row SCREEN Creates a new screen. A bitplane is? A screen contains an overlapping number of bitplanes A screen has a fixed number of bitplanes. The number of bitplanes gives the maximum number of colours that can appear on the screen at the same time. The number is 2^n, where n is the number of bitplanes. The minimum is 2,the Workbench default is 4 and the maximum is 32, when there are 5 bitplanes. Different values for height and width can be given. It is recommended to use 640 or 320 for the width and 240 or 480 for the height( or 200 and 400 for NTCS screens). Using other values may appear to work in the short term, but can lead to unusual results and is not recommended. Screens vary in resolution. This is set by the mode. A screen may be low resolution, medium resolution or high resolution. (Lo-res,med-res or hi-res). Each of these resolutions may be with or without interlace. Normally a pixel is a rectangle which is twice as tall as it is wide. When interlace mode is used pixels become square. Screens are numbered 1 to 4.(There cannot be more than 4). The default is the workbench screen, which is screen -1. SCREEN CLOSE After a screen is finished with it should be closed with the screen close command to help save memory. SCROLL This moves part of the screen in any direction. The shape moved is a rectangle. q 1001111001 QUIZ ON SCREENS Type 1 for true, 0 for false (1) The number of colours is determined by the number of bitplanes (2) There can be any number of screens (3) SCROLL moves part of a window (4) The screen resolution is set by the mode (5) The width should be 640 or 320 pixels (6) SCROLL can only move rectangular sections (7) The workbench screen is screen -1 (8) Any values can be used for the height and the width (9) Screens cannot be closed (10) When interlace mode is used, a pixel changes its shape WINDOW Window-id gives the identification number of the window. No more than 1 window can have the same number. This number must be greater than 1, as 1 is original screen window. Title-this name appears in the window title bar A title of"" gives no title. Co-ordinates gives co-ordinates in the same way as drawing a box. STEP cannot be used as in the LINE statement. The window number is a number between 1 and 32. The window number gives value of window e.g. whether it has a close gadget or not. There can be any number of windows. Windows can appear on top of other windows. See manual for more details. The last number gives the screen the window appears on. If the number is left off it appears on the workbench screen(screen -1). If a new screen is created, it will not be brought to the foreground until 1 or more windows appears on it. The current window and the ouput window, may be the same window, but may be different windows. WINDOW OUTPUT id Directs output to that particular window. WINDOW CLOSE id Removes that particular window. WINDOW returning window values Window(0) gives the window id of the window that was last clicked in with the mouse. q 01011 QUIZ ON WINDOWS Type 1 for true, 0 for false (1) 2 windows may have the same id number (2) Windows are always rectangular (3) The current window and the output window are always the same (4) A WINDOW statement incude the top left and bottom right co-ordinates (5) Each window has a different number GET This can be used to place a graphic that has already been drawn, into an array. The array is onedimensional and must have a minimum number of elements. This number can be calculated by bitplanes*etc,etc It gets whatever is on the screen in the rectangle formed by the given co=ordinates. (The rectangle is formed in the same way as a rectangle drawn with the line command, using the co-ordinates of the top-left corner and the bottom right corner). PUT After a graphic has been stored with get it can be placed anywhere on the screen, at any time put simply puts the graphic in the rectangle of the given co=ordinates. A graphic may be put any number of times. The following commands determine the relationship between the graphic and the background it is placed on GET AND PUT/ANIMATION GET and PUT can be used to create a limited form of animation by placing a picture, removing it, placing it in a new position etc. (GET and PUT are not to be confused with GET and PUT commands related with random files). q 01010 QUIZ ON GET AND PUT Type 1 for true, 0 for false (1) PSET combines the foreground and the background (2) The default command for put is XOR (3) PUT stores a graphic in an array (4) PRESET switches the foreground and background colours (5) XOR places the graphic exactly how it is PSET Places the graphic exactly as it is without altering the background PRESET Inverts the colours of both the background and the foreground XOR (mutually exclusive) is the default Places the graphic exactly as it is without altering the background AND Combines the foreground and the background. OR 'ac basic book for this q 01010 QUIZ ON GET AND PUT Type 1 for true, 0 for false (1) PSET combines the foreground and the background (2) The default command for put is XOR (3) PUT stores a graphic in an array (4) PRESET switches the foreground and background colours (5) XOR places the graphic exactly how it is LINE LINE draws a line from x,y to x1,y1. The first two points gives the starting location while the second pair of points gives the ending location. if y=y1 then a horizontal line is drawn. e.g. LINE(100,50)-(200,50) LINE (100,50)-(200,50) IF x=x1 THEN a vertical line is drawn. IF y=y1 THEN a horizontal line is drawn. IF both values are different a diagonal line is drawn q 01010 QUIZ ON GET AND PUT Type 1 for true, 0 for false (1) PSET combines the foreground and the background (2) The default command for put is XOR (3) PUT stores a graphic in an array (4) PRESET switches the foreground and background colours (5) XOR places the graphic exactly how it is STEP Means the new values of x and y are relative to the previous values. The values given after STEP are added to the old ones. They can be positive, negative or zero. THere must be previous values for the STEP to refer to! This applies to the LINE,CIRCLE,AREA and other graphics statements. e.g. LINE(100,50)-STEP(100,0) In the above example the line starts at 100,50 and ends at 200,50 q 01010 QUIZ ON STEP Type 1 for true, 0 for false (1) PSET combines the foreground and the background (2) The default command for put is XOR (3) PUT stores a graphic in an array (4) PRESET switches the foreground and background colours (5) XOR places the graphic exactly how it is RECTANGLES The line statement can be used to draw rectangles. B draws a box with x,y being the top left corner. and x1,y1 being the bottom left corner. Bf fills a box with the given colour. Workbench colours are 0-blue,1-white,2-black,3-orange Adding a number indicates the colour it is to be filled If the number is omitted, the foreground drawing colour is used to draw the box. e.g. LINE(40,20)-(80,40),3,bf A box is drawn and filled with colour 3(orange). q 11000 QUIZ ON LINES Type 1 for true, 0 for false (1) Lines can drawn relatively or absolutely (2) A rectangle can be drawn with one statement (3) Lines cannot be drawn with variables (4) Lines cannot be drawn diagonally (5) A pixel is twice as wide as it is high LINE and loops FOR x=100 TO 600 STEP 50 LINE(x,0)-STEP(0,100) NEXT nested loop FOR x=50 TO 150 STEP 50 FOR y=25 TO 75 STEP 25 LINE(x,y)-STEP(0,25) LINE(x,y)-STEP(50,0) NEXT NEXT USING DATA VARIABLES Lines (and other graphics) can be drawn by using variables instead of constants and reading data items. e.g. read a,b,c,d line(a,b)-(c,d) data 10,40,55,30 q 01010 QUIZ ON GET AND PUT Type 1 for true, 0 for false (1) PSET combines the foreground and the background (2) The default command for put is XOR (3) PUT stores a graphic in an array (4) PRESET switches the foreground and background colours (5) XOR places the graphic exactly how it is CIRCLE Draws a circle with its centre at the given x and y co-ordinates with the given radius. You can add the colour the circle is to be drawn with. STEP can be used as in a LINE statement. Aspect is the ratio of the width to the height of a pixel. (This can depend on the monitor). using -.44 will draw a perfect circle Ellipses can be drawn. Arcs or segments of a circle can be drawn. q 01011 QUIZ ON CIRCLES Type 1 for true, 0 for false (1) AREA draws curves between different points (2) Coloured circles can be drawn (3) CIRCLE cannot be used to draw arcs (4) A shape drawn with AREA could have been drawn with line statements (5) The CIRCLE command could be used to draw part of an ellipse AREA Draws a polygon with the given vertices. There can be no more than 17 points drawn. This is an alternative to using LINE statements and uses less code. AREAFILL If the polygon is solid, you can fill it with the given colour with one statement q 01011 QUIZ ON AREA Type 1 for true, 0 for false (1) AREA draws curves between different points (2) Coloured circles can be drawn (3) CIRCLE cannot be used to draw arcs (4) A shape drawn with AREA could have been drawn with line statements (5) The CIRCLE command could be used to draw part of an ellipse PALETTE Changes the mixture of a colour, but does not alter the number of different colours that can be displayed on the screen at any one time. The AMIGA can produce 4096 different colours (16x16x16 of each of the red,green and blue components(thats why they call it an RGB monitor!) Amigabasic rounds these 1/16s to the nearest .1 so that Amigabasic can create only 1000 different colours. Hence each colour is composed of a red,green and blue value, each of which is between 0 and 1. By altering thee values you can get any of the 4096 colours of the amiga e.g.palette 1, .3,1,0 The higher the number, the darker it is and the lower the lighter it is. By giving zero to 2 of the 3 values, you will get either a pure red, green or blue. By mixing 2 or 3 of these you can create different mixtures. As RND generates numbers between 0 and .1, it is ideal for use with PALETTE. q 11010 QUIZ ON PALETTE Type 1 for true, 0 for false (1) PALETTE changes the red,green and blue values (2) The first number of PALETTE gives the colour number (3) PALETTE can be used to create any of the 4096 colours available (4) PALETTE uses numbers between 1 and 0 (5) The higher the number, the lighter the colour PAINT This paints an area, starting at the given co-ordinates(in pixels) with the given colour It continues to paint until reaching the edge of the screen or a drawn line or the screen etc. If the co-ordinates are not within an enclosed object, the paint will `leak' and fill the entire screen A gap of 1 pixel is sufficient to cause a leak. A leak means that the filling colour will escape and fill areas that it should not, perhaps the whole window. Leaks need to be fixed! When the co-ordinate is within an enclosed shape the second number will paint the boundary colour the given colour. q 01011 QUIZ ON PAINT Type 1 for true, 0 for false (1) PAINT can fill several windows simultaneously (2) PAINT should be used inside a solid object (3) PAINT cannot use the colour 0 (4) PAINT starts filling from the given co-ordinates (5) PAINT can colour the interior and boundary COLOR The first number gives foreground colour, the second number gives background colour. The background coour is the colour of the screen while the foreground colour is what everything placed on the screen whether it is text or graphics. The colour corresponding to a number is determined by the original colour mix and may have been altered by a PALETTE command. Anything that is placed on the screen after this command, whether it is drawn or written, will appear in the foreground colour. This may be changed by another COLOR statement. It is useful to fill the whole screen with a PAINT command first If a color statement is followed by text the text will appear in a coloured bar. This can be effective in conjunction with the PALETTE statement. Only applies to the current window. q 10010 QUIZ ON COLOURS Type 1 for true, 0 for false (1) COLOR uses 2 values (2) Text is written in the background colour (3) COLOR can be used to create any of the 4096 colours available (4) Graphics are drawn with the foreground colour (5) The second number in COLOR is the foreground colour POINT This returns the number of a colour(the colour-id) at point(x,y). If the point is outside the value returned will be -1. One use of this could be to scan what the user had done in a drawing program? PATTERN Can be used to fill an area with a given pattern, in the same way paint can paint an area. Pattern can also to be used to alter the texture of text and lines. The line-pattern is a 16 bit area that is repeated, until the specified area is filled. The value of the 16 bit need not be a power of two. The area-pattern is the name of the array which contains the pattern. The array is 16 bits wide by a number(the number of elements in the array) high. This number must be a power of two. The values for these 2 variables create the resulting pattern. Numeric, hexaecimal or octal numbers can be used to describe the pattern Octal numbers are base 8. Hexadecimal numbers are base 16. q 11100 QUIZ ON POINT AND PATTERN Type 1 for true, 0 for false (1) POINT only aplies to pixels in the current window (2) A pattern is composed of 16 bit areas. (3) Hexadecimal numbers can be used to describe a pattern (4) The number of the line-pattern must be a power of 2 (5) POINT can be used to find the colour-id of any pixel