Hila Research Centre

Computer Programming

Graphics with Qbasic

Images on a computer screen are created by controlling illuminated spots on the screen called pixels. You can use Qbasic to control pixels. Most monitors (computer screens) have 350 rows of pixels, each row is 640 pixels long. This creates a total of 224,000 pixels on the screen!

Each pixel has an address that looks like this: (200,100), this is the address for the pixel that is 200 pixels over (from the left) and 100 pixels down (from the top).

Let's turn this pixel on. Type in the following three line program and run it (press F5).

CLS

SCREEN 9

PSET (200,100)

CLS - Clears the screen when the program starts.

SCREEN 9 - You must start each graphics program with this command.

PSET (200,100) - Turns on the pixel located 200 over, 100 down.

SUMMARY OF GRAPHICS COMMANDS

SCREEN 9 - 640 x 350 pixel graphics mode (Start all graphics programs with this.)

PSET (200,100) - Turns on the pixel located 200 over (from left) and 100 down.

LINE (10,10) - (300,250) - Draws a line between pixel locations (10,10) & (300,250)

LINE (50,10) - (100,75), ,B - Draws a box with line as diagonal.

CIRCLE (320,175),100 - Creates a circle, centered at (320,175) with a diameter of 100 pixels.

COLOUR CONTROL

Colours are represented by 16 numbers:

0 - black, 1- blue, 2 - green, 3 - cyan, 4 - red, 5 - magenta, 6 - brown, 7 - white, 8 - gray, 9 - light blue, 10 - light green, 11 - light cyan, 12 - light red, 13 - light magenta, 14 - yellow, 15 - bright white.

Try the following colour commands.

COLOR 4,10 - Changes screen colours to red foreground on green background. Note spelling of COLOR command.

PSET (125,90), 14 - Creates a yellow pixel

LINE (10,20) - (70,100), 1 - Draws a blue line.

LINE (100,100)-(200,320), 2, B - Creates a green box.

CIRCLE (200,200), 50, 4 - Creates a red circle.

PAINT (200,200), 2, 4 - Fills the above circle with green, stopping at the red border.

Back to Projects Menu