What can QBasic do in the way of Graphics
QBasic is not that much graphically good, however many good programs can be created with it. Commands like PSET, CIRCLE, LINE, etc., are used to draw graphics in Qbasic. One of the good programs created using QBasic is SYMMETRIC ICON and SYMMETRIC FRACTALS.
The PSET Command
The PSET command lets the programmer display pixels on the screen. Before you type the command in, you must make sure that a SCREEN command is in. Look at this example:
SCREEN 13 PSET (1,1), 43
This command will display one red pixel at the coordinates 80, 20. The coordinates are X and Y coordinates, like any other mathematical situation. So the PSET command has to have this layout to function properly:
PSET ([X coordinate], [Y coordinate]), [Colour of Pixel]
Remember that X coordinates are those that go left to right on the screen and Y coordinates are those that go Up to Down on the screen.
The LINE Command
This simple command displays a line. It can be in a command like this:
SCREEN 13 LINE (16, 24) - (40, 30), 1 BF
This simple program will input a line on the screen. For an in depth knowledge of what the numbers mean, look at this layout:
LINE ([X 1], [Y 1]) - ([X 2], [Y 2]), [Colour Number] '1 Being the start of the Line '2 Being the End of the line
Like the PSET command you MUST put a SCREEN command.
The CIRCLE Command
CIRCLE (20, 25), 5, 1
This displays a circle at the coordinates. The layout of the function is as follows:
CIRCLE ([X Coordinate], [Y Coordinate]), [Radius], [Colour Number]
Remember to put a SCREEN command at the front.
The PAINT command
To use PAINT, there must be a SCREEN command declared. The command has coordinates that tells QBasic where to start. The color number specifies the color to paint with, and the bordercolor tells the PAINT command that it should not paint further when it encounters a pixel of that color. In almost all cases, you will need to use the bordercolor parameter, simply because without it, PAINT will cover the entire screen.
PAINT ([X Coordinate],[Y Coordinate]), [Color Number], [Border Color]1,2,3,4,5,5
Making An Image Using the DATA command
Graphics using this command can either be made by using a Graphics Editor or by using the DATA command Manually. The DATA command is a way of inputting information into QBasic and being read by the READ command. Remember that the DATA command cannot be used in subroutines or functions. Look at this example:
SCREEN 7 FOR y = 1 TO 10 FOR x = 1 TO 10 READ z PSET (x, y), z NEXT NEXT DATA 04, 04, 04, 04, 04, 04, 04, 04, 04, 04 DATA 04, 00, 00, 00, 00, 00, 00, 00, 00, 04 DATA 04, 00, 00, 00, 00, 00, 00, 00, 00, 04 DATA 04, 00, 00, 00, 00, 00, 00, 00, 00, 04 DATA 04, 00, 00, 00, 00, 00, 00, 00, 00, 04 DATA 04, 00, 00, 00, 00, 00, 00, 00, 00, 04 DATA 04, 00, 00, 00, 00, 00, 00, 00, 00, 04 DATA 04, 00, 00, 00, 00, 00, 00, 00, 00, 04 DATA 04, 00, 00, 00, 00, 00, 00, 00, 00, 04 DATA 04, 04, 04, 04, 04, 04, 04, 04, 04, 04
The FOR commands declare the amount of pixels there are to be read. On this particular program, there are pixels of 10 by 10 (100) so we put:
FOR x = 1 TO 10 FOR y = 1 TO 10
We have now declared the x and y planes. You can change these values if you want a smaller or bigger picture Bitmap. The READ command reads the DATA commands and declares the information gathered as z.
The PSET reads the planes and the DATA read and a bitmap.
PSET (x, y), z
It works like the first example on this page, except it is reading more than one pixels