QBasic allows your program to make use of your graphics display monitor and the speaker on your personal computer.
QBasic allows you to use the screen on your monitor in several different modes. These modes are identified by numbers. By default, QBasic uses mode 0 for the screen. In mode 0, the screen is a grid of 80 columns and 25 rows. Your program can write to each of these grid locations. The top left corner of the screen is the location (1, 1), i.e., row 1, column 1. The bottom right corner of your screen is (80, 25), i.e., column 80, row 25. Notice that the co-ordinates for a grid location are specified by first writing the column number, and then the row number. In mode 0, you can specify printing characters at grid locations. This does not allow you to make use of the resolution of your monitor. Monitors actually display information by drawing dots on pixels (picture elements). To be able to use a higher resolution for the screen from your programs, you should use either mode 1 or mode 2. The SCREEN statement allows you to change the graphics mode that your program uses. The statement
In graphics mode 1, the resolution of the screen is 320 columns and 200 rows of pixels. The co-ordinates of the top, left corner pixel are (0, 0) and the co-ordinates of the bottom, right corner pixel are (319, 199). Once again, in writing co-ordinates, the column number (or X-coordinate) is written first and then the row number (or Y-co-ordinate). Also, notice that the column and row numbers start at 0.
In graphics mode2, the resolution of the screen is 640 columns and 200 rows of pixels, giving you twice the number of columns as graphics mode 1. The co-ordinates of the top, left corner pixel are (0, 0) and the co-ordinates of the bottom, right corner pixel are (319, 199).
QBasic has statements to let you draw basic figures on the screen. When you start a graphics mode with a SCREEN command, there is a default background colour (black) and a default foreground colour (white) assigned to the screen. All that you draw or print from your QBasic program is in the foreground colour. In graphics mode 1, QBasic allows you to choose a colour for your background and a palette of colours for the foreground with the command COLOR. For more information see the description of the command COLOR under Help in QBasic.
Below is a brief description of some of the commands for drawing simple objects such as points, lines, circles, etc. For more information on each of these command, see the description of the command under Help in QBasic.
The QBasic command to draw a point is PSET. The command
The command PRESET erasee the point at the specified co-ordinates. Actually, it draws the point in the background colour, hence giving the feeling that the point was erased. For example, the command
The CIRCLE command also provides a mechanism for drawing arcs, i.e., not complete circles. To do this, you have to specify the starting angle of the arc from the positive X axis and the ending angle of the arc from the positive X axis. The angles have to be specified in radians.. For example, the command
Back to Fall 95 Coursework