QBASIC GRAPHICS


The World today is a world of Graphics. We have now moved from the world of only text to the world of animations, movies and images.

QBASIC is a powerful programming language that provides the programmer an opportunity to display both text as well as graphics on the screen with different colours.

Graphics in QBASIC:

§  A graphic is an image or visual representation of an object.

§  Graphics on the screen can be drawn with the help of predefined commands called as Graphic Statements in QBASIC.

§  Before learning the various Graphic Statements, let us understand the meaning of a Pixel and Screen Resolution.

§  A Pixel (px) is the smallest portion of an image or picture on the computer screen.

§  The maximum number of pixels that can be displayed vertically or horizontally on a computer screen is termed as Screen Resolution.

§  For Example: A Screen Resolution 640 * 480 for an image would mean 640 pixels in horizontal direction and 480 pixels in a vertical direction.

Graphic Statement in QBASIC:

The Graphic Statements are used in QBASIC program to draw graphics on the screen. These Statements are as follows:

§  SCREEN Statement

§  COLOR Statement

§  PSET Statement

§  LINE Statement

§  DRAW Statement

§  CIRCLE Statement

§  PAINT Statement

SCREEN Statement:

§  The SCREEN Statement initiates the environment to display graphics in QBASIC.

§  The SCREEN Statement loads the graphics hardware for the other graphics statements to be executed.

§  A program must have a SCREEN Statement before any other graphic commands.

§  The Syntax of the SCREEN statement is as follows:

§  SCREEN [MODE]

where,

·         MODE is any number within 1 to 13.

§  QBASIC supports several screen modes, which affect the resolution, color and display of a text or graphic.

§  If the value of the MODE is 0, It will display only text.

§  If the value is between 1 to 13, it will display only graphics.

§  There are two types of Screen Modes namely TEXT MODE and GRAPHIC MODE.

§  The TEXT MODE can display only text.

§  The GRAPHIC MODE can display both graphics and text.

§  Each Screen Mode displays different screen resolutions.

The various Screen Modes are given below:

Screen Mode

Screen Type

Screen Resolution

Colors

SCREEN 0

Text Screen

It cannot be used for graphics.

SCREEN 1

Graphics

320 * 200

4

SCREEN 2

Graphics

640 * 200

2 (BLACK and WHITE)

SCREEN 7

Graphics

320 * 200

16

SCREEN 8

Graphics

640 * 200

16

SCREEN 9

Graphics

640 * 300

16

SCREEN 10

Graphics

640 * 350

2 (BLACK and WHITE)

SCREEN 11

Graphics

640 * 480

2 (BLACK and WHITE)

SCREEN 12

Graphics

640 * 480

16

SCREEN 13

Graphics

320 * 320

256

COLOR Statement:

§  The COLOR Statement is used to set foreground color, background colorand border color for various screen modes.

§  The Syntax of COLOR Statement is as follows:

COLOR [NUMBER]

Where,

NUMBER is the value between the range 0 to 15.

The 16 colors that are used in QBASIC are given below.

§  00 CODE is for BLACK Color.

§  01 CODE is for DARK BLUE Color.

§  02 CODE is for DARK GREEN Color.

§  03 CODE is for DARK CYAN Color.

§  04 CODE is for DARK RED Color.

§  05 CODE is for DARK PURPLE Color.

§  06 CODE is for ORANGE BROWN Color.

§  07 CODE is for GREY Color.

§  08 CODE is for DARK GREY Color.

§  09 CODE is for LIGHT BLUE Color.

§  10 CODE is for LIGHT GREEN Color.

§  11 CODE is for LIGHT CYAN Color.

§  12 CODE is for LIGHT RED Color.

§  13 CODE is for MAGENTA Color.

§  14 CODE is for YELLOW Color.

§  15 CODE is for WHITE Color.

PSET Statement:

§  The PSET Statement stands for Pixel Set.

§  A Pixel is the smallest element of a picture.

§  This statement is used to display a pixel on the screen with the specified color.

§  The Syntax of PSET Statement is as follows:

PSET([X coordinate], [Y coordinate], [Pixel Color])

Where,

·         X coordinate: It is the value of the X coordinate of a pixel.

·         Y coordinate: It is the value of Y coordinate of a pixel.

LINE Statement:

§  The LINE Statement displays a line.

§  The LINE Statement requires the starting co-ordinates the ending co-ordinates and the color if desired.

§  The Syntax of LINE Statement is as follows:

LINE([X 1], [Y 1])-([X 2], [Y 2]),[COLOR NUMBER]

Where,

§  X1 is the X co-ordinate for the first point.

§  Y1 is the Y co-ordinate for the first point.

§  X2 is the X co-ordinate for the second point.

§  Y2 is the Y co-ordinate for the second point.

§  COLOR Number is the color of line.

DRAW Statement:

§  The DRAW Statement provides an easy way to draw complex graphics.

§  DRAW Statement allows you to draw lines, shapes and fill colors.

§  The Syntax of the DRAW Statement is as follows:

DRAW “CN, DN, RN, UN, LN”

Where,

·         CN is the color to set.

·         DN is the value to move downward.

·         RN is the value to move right.

·         UN is the value to move up.

·         LN is the value to move left.

CIRCLE Statement:

§  The CIRCLE Statement in QBASIC allows you to draw circles of various sizes and colors.

§  The Syntax of CIRCLE Statement is as follows:

CIRCLE(X-co-ordinate, Y co-ordinate), Radius, COLOR Number

Where,

·         X co-ordinate is the X co-ordinate.

·         Y co-ordinate is the Y co-ordinate.

·         Radius is the radius of the circle.

·         COLOR Number is the color of the circle.

PAINT Statement:

§  The PAINT Statement fills closed areas on the screen with a specified color.

§  It is used to paint a particular point or portion of the graphic with the specified color.

§  The Syntax of PAINT Statement is as follows:

PAINT ([X co-ordinate], [Y co-ordinate], [COLOR Number], [BorderColor] 1,2,3,4,5)

Where,

·         X co-ordinate is the X co-ordinate of a Paint region.

·         Y co-ordinate is the Y co-ordinate of a Paint region.

·         COLOR Number is the color for a PAINT region.

·         Border Color is the bordercolor of a PAINT region.

Advertisements