What QBasic can do with Graphics

edit

QBasic is not graphically very capable but many good programs can be created with it. Commands like PSET, CIRCLE, LINE, etc., are used to draw graphics in QBasic. Good examples of graphical programs created using QBasic are SYMMETRIC ICON and SYMMETRIC FRACTALS.

Functions

edit

Screen will let you set how it will be used. Text Graphics, both, and the Size of the surface you are working with. Screen 0 .. means Text Only. Screen 12 .. means 64 X 480 X 16 Colors & Text.

PSET

edit

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 yellow pixel at the coordinates 1, 1. 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.

LINE

edit
   LINE [[STEP](x1!,y1!)]-[STEP](x2!,y2!) [,[color%] [,[B | BF] [,style%]]]
   STEP          Specifies that coordinates are relative to the current
                   graphics cursor position.
   (x1!,y1!),    The screen coordinates of the start of the line and of
   (x2!,y2!)     the end of the line.
   color%        A color attribute that sets the color of the line or
                   rectangle. The available color attributes depend on your
                   graphics adapter and the screen mode set by the most
                   recent SCREEN statement.
   B             Draws a rectangle instead of a line.
   BF            Draws a filled box.
   style%        A 16-bit value whose bits set whether or not pixels are
                   drawn. Use to draw dashed or dotted lines.

This simple program displays a line:

  Screen 13 
  LINE (160,10)-(100,50),13 
 
Simple Line

CIRCLE

edit
CIRCLE (100, 100), 25, 4,0,3.14

This displays a circle at the coordinates. The layout of the function is as follows:

CIRCLE ([X Coordinate], [Y Coordinate]), [Radius], [Colour Number],[Start Angle],[Finish Angle]

Remember to put a SCREEN command at the front.

PAINT

edit

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

DRAW

edit

ToDo

Making An Image Using the DATA command

edit

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.

READ 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