Whilst the commands for positioning and printing text on the screen are similar to other versions of BASIC (TAB and PRINT), BBC BASIC (Z80) has an extensive range of graphics commands. These commands are similar to those available on a BBC Micro, but different from many other versions of BASIC.
As this version of BBC BASIC only works with a monochrome display, there are only two colours - black and white. However, certain graphics operations that fill regions (such as the rectangle or circle filling operations) can fill using a dithered pattern.
Colours values are in the range 0 to 15. 0 is black and 15 is white; values in-between depend on the drawing operation.
- For text and traced shapes (eg lines and unfilled circles) colours 0 to 7 are black and colours 8 to 15 are white.
- For filled shapes (eg filled circles and filled rectangles) the colour specifies a dither pattern.
Colours can be reset to their default values with the VDU 20 command.
The following snippet can be used to set a greyscale palette in BBC BASIC for Windows that mimics the dithered palette in the calculator version.
FOR C%=0 TO 15 COLOUR C%,C%*16+C%,C%*16+C%,C%*16+C% NEXT C%
You can instruct BBC BASIC to fill shapes using an 8×8 pixel pattern of your own design with the GCOLPAT keyword. This pattern will replace the foreground and background colour in plotting operations that fill shapes - outlined shapes are not affected.
Drawing on the Screen
The Graphics Area
BBC BASIC (Z80) has a logical graphics area (or 'internal' screen) with a size of +32767 to -32768 in both the X and Y axis. The graphics window, the graphics origin and the current graphics cursor position may be anywhere within this graphics area.
The physical screen is a window on the graphics area. Its 'logical' size depends upon the window mode selected and it is much smaller then the graphics area.
By default the graphics origin is in the bottom-left corner of the display with the X axis pointing right and the Y axis pointing up. Coordinates are expressed in logical units rather than physical units. For example, in the default MODE 0 the display has a logical resolution of 384×320, putting the point (192,160) in the centre of the display. The graphics origin can be moved with the VDU 29 command, the scaling of logical units to physical units can be set with the *GSCALE command and the orientation of the Y axis can be changed with the *YAXIS command.
Graphical operations act on a user-definable window. By default this window is the full size of the screen. You may change the size of the graphics window with the VDU 24 command.
More information may be found in the Windows section.
You can move or draw to any point which is within the graphics area whether or not this point is outside the current graphics window. If you draw a line to a point outside the graphics window, the line is not displayed beyond the boundary of the window.
You can use the DRAW statement to draw a straight line on the screen. The statement is followed by the X and Y coordinates of the end of the line.
The start of the line is the current graphics cursor position. This is either the end of the last line drawn or a point specified by a MOVE statement.
The line is drawn in the current graphics foreground colour. This colour can be changed using the GCOL.
MOVE 20,30 DRAW 64,80
The DRAW statement is identical to PLOT 5.
You can move the graphics cursor to an absolute position without drawing a line with the MOVE statement.
MOVE X,Y MOVE 12,32
The MOVE statement is identical to PLOT 4.
PLOT is a multi-purpose drawing statement. Typically, three numbers follow the PLOT statement: the first specifies the type of point, line or shape to be drawn; the second and third give the X and Y coordinates to be used.
The available PLOT modes are listed in its keyword reference.
The POINT function returns a number giving the logical colour of the screen at the coordinates specified. If the point is outside the display, then -1 is returned.
There must not be a space between POINT and the opening bracket.
See the POINT keyword reference for more information.