Graphics in Basic

Graphics is Associate in Nursing art to style and turn out picturing of knowledge. Graphics is displaying data on the screen. Graphics is one vital a part of the GW_-BASIC language. Graphics suggests that photos that may be drawn on the‘ screen,‘ and ‘all fashionable laptop languages have directions that permit you to draw such patterns. ‘

Graphic Depends on the Hardware like input, output and Graphic cards (Color Graphic adapter, Video Graphic Adaptor). Most microcomputers. use a television monitor (CRT) as a primary output device. Monitor screen created from many pixels. the quantity of pixels horizontally and vertically determines the resolution of your monitor. A constituent is one dot on the screen. Any screen coordinate will be determined by numeration the ranges of pixels down and therefore the number of pixels to the proper. V

Graphic Modes

The quality of the colour graphics adapter (CGA) monitor is to supply 3 differing kinds of modes for displaying image or diagram on a screen.

The 3 varieties of modes square measure as follows: –

1 -Text Mode

2-Medium Resolution Graphic Mode

3-High Resolution Graphic Mode

1- Text Mode

Text mode is employed for less than matter knowledge i.e. Text Mode permits the show of letters, numbers, and every one characters within the ASCII character set, however isn’t used; for displaying graphics. In text based mostly graphic, text and features will be drawn on the; screen. during this mode the screen has the capability of displaying’25 lines and every line with eighty characters. This makes 25×80 matrix. Text “mode has sixteen, colours out?’ of any two colours palettes. Columns square measure counted from zero to thirty-nine or seventy nine and rows from zero to twenty four. Text mode uses SCREEN zero statement.

2-Medium Resolution Graphic Mode

Medium resolution graphic mode is employed in drawing graphics. The video display is split into a matrix consisting of 320 columns and two hundred rows of pixels. The position of every and each constituent are going to be determined by its coordinates on coordinate axis and coordinate axis of the screen. Medium resolution graphic mode works with four colours i.e. 04, l, 2, 3,’ one among sixteen color will chosen for background and one for foreground. Medium resolution graphic mode uses SCREEN one statement. It supports each EGA and CGA.

3-High Resolution Graphic Mode

High resolution graphic mode is employed in drawing graphics with matrix of 640* two hundred pixels. we tend to square measure ready to show the text characters in twenty five lines of eighty characters in every line. High resolution graphic mode uses SCREEN two statement. It supports each EGA and CGA. It supports assignment of sixteen colours to any of two attributes

Q.2: -Describe Screen statement.

Ans.: -Screen Statement
The SCREEN statement is usually accustomed choose a screen mode applicable for a selected show hardware configuration. The first statement to be utilized in any graphics program may be a SCREEN statement. This statement

makes the pc prepared for the graphic operation. Resolution of _the screen (number of row and column), range of color attainable and whether or not constituent graphic or text graphic is feasible depends on the screen statement. The screen statement permits the applied scientist to pick out totally different show modes.

Syntax:

SCREEN [mode] [, [colorswitch] ]

Where screen mode may be a numeric price from zero, 1, 2, 7, 8, 9, 10. it should not be run on every sort of laptop or monitor, as a result of it depends on the show card and monitor’s sort.

SCREEN Modes

Here mode may be a numerical price, mode will have price O, 1 ,2,7,8,9 or l0. betting on the monitor and therefore the show card (adapter) being .used a number of these modes could or might not be attainable.

SCRREN zero Statement

SCREEN O statement is employed solely in text mode, that is additionally the default -mode. Text mode has eighty columns and twenty five rows. This mode doesn’t permit any constituent based mostly graphics.

SCREEN one Statement

SCREEN l statement is employed to activate the medium resolution graphic mode. Medium resolution graphic mode has 320 columns and two hundred rows. This mode is employed for graphics. Text is feasible in forty columns by twenty five rows. It supports four colours. This mode needs CGA, EGA or VGA display adapter cards.

SCREEN two Statement

SCREEN two statement is employed to activate the High resolution graphic mode. High resolution graphic mode has 640 columns and two hundred rows. This mod is employed for graphics. Text is feasible in eighty columns by twenty five rows. It supports colours. This mode needs CGA, EGA or VGA display adapter cards. ‘

SCREEN seven Statement

SCREEN seven statement is employed to activates the medium resolution graphic mode with sixteen colours. This mode will have 320 columns by two hundred rows pix graphic. Text is feasible in forty columns by twenty five rows. This mode supports l colours. This mode needs EGA or VGA display adapter cards.

SCREEN eight Statement

SCREEN eight statement is employed to activates the High resolution graphic

mode with sixteen colours. This mode will have 640 columns by two hundred rows constituent graphic. Text is feasible in eighty columns by twenty five rows. This mode supports sixteen colours. This mode needs EGA or VGA display adapter cards.

SCREEN nine Statement

SCREEN nine statement is employed to activates the improved resolution graphic mode. This mode will have 640 columns by 350 rows constituent graphic. Text is feasible in eighty columns by twenty five rows. This mode supports sixteen colours if the show card has over 64K memory otherwise you get four colours. This mode needs EGA or VGA display adapter cards.

SCREEN ten Statement

SCREEN ten statement is employed to activates the improved resolution graphic mode. This mode will have 640 columns by 350 rows constituent graphic. Text is feasible in eighty columns by twenty five rows. this is often a monochrome mode. It supports four attributes. This mode needs EGA or VGA display adapter cards.

Q.3: – Describe Color statement.

Ans.: -COLOR Statement

The purpose of COLOR statement is to pick out show colours. If you’ve got a color monitor, you can, of course, show each text and graphics in color. If you’re employing a monochrome monitor, then the colours can seem solely as reminder black and white. the selection of color will be specified by the colour statement.

Syntax:

COLOR [foreground] [, [background] [, border]]

COLOR [background] [,[palette]]

COLOR [foreground] [,[background]]

In general, COLOR statement permits you to pick out the foreground and background colours for show. In SCREEN zero a border color can even be hand-picked. In SCREEN l no foreground color will be hand-picked, however one among 2 four color palettes will be hand-picked to be used with graphics statements.

For a text screen SCREEN one, the order of numbers is foreground, background; border and therefore the that means of the numbers square measure shown below the table.

CODE COLOR CODE COLOR

0 BLACK eight grey

1 BLUE nine lightweight BLUE

2 inexperienced ten lightweight inexperienced

3 CYAN eleven lightweight CYAN

4 RED twelve lightweight RED

5 MAGENTA thirteen lightweight MAGENTA

6 BROWN fourteen YELLOW

7 WHITE fifteen BRIGHT WHITE

These color statements can create the foreground color lightweight magenta, the background dark magenta, and therefore the border blue. This extremely is helpful solely on a color monitor, as a result of the contrasts aren’t therefore helpful on a monochrome monitor. once doing the graphic work if you would like to show the photographs in several colours then COLOR and PALETTE statement will be accustomed specify the precise color needed. GW-BASIC cannot show every each|and each} alter every mode. supported the screen mode, COLOR statement works otherwise as shown below.

Screen zero (Text Mode)

If you’re in text mode (mode 0) the behavior of the colour statement is as shown below, the colour statement format for the text mode (mode O) is

COLOR foreground, background, border

Here foreground color is that the color exploitation that the text or image seem.

Background color is that the color of the screen on that the image or text seems.

Border color is that the color of the border round the screen.

Foreground color will have values from O to thirty one. Color zero to fifteen offer totally different colours as shown within the next table. once the quantity sixteen is more to those color codes you get a blinking version of that individual color. as an example if the colour four is red then the colour 4+16 or color twenty can provides a blinking red color.Blinking color is that the color that keeps on happening and off
Background color allowed during this mode is color zero to seven. Border color will have price zero to fifteen. Background and border don’t permit blinking color
Screen one (Medium resolution graphic mode)

In case the medium resolution mode is employed, then the choices allowed with color statement is as shown below

COLOR background color, palette

In this mode background color is specified first. The background price will be any color price from zero to l5. when the background color, a palette of three colours is specified. This palette price will be either zero or one.This palette range selects one among the 2 attainable sets of foreground colours. colours from totally different palettes can’t be displayed at constant time on the screen. as an example color inexperienced from palette O and color cyan from palette two can’t be displayed along on the screen.

In CGA Mode

When the palette price is O, color can show inexperienced ‘color. Color two can show red color. Color three can show yellow color. to urge a selected color, first use the colour statement to specify the background and therefore the needed palette price, then use these color range can the graphic statement, like CIRCLE,

LINE etc. to show them in color

For example

SCREEN 1

COLOR 1,1

Will create the backgroundrcolor blue and therefore the palette one getting used. because the palette one is employed, it’ll choose the palette one possibility.

CIRCLE (200,40),30,2 A

Statement draw a circle with color two as define (palette one color two can show magenta color)

COLOR 7, 0

LINE (30,10)-(1i10,10),2

The on top of color statement can first create the background white (color 7) and it’ll choose palette zero. Next, LINE statement can draw a line exploitation color two from the palette zero. because the color two in palette zero is red, you may get a line one white background.

Screen two (High resolution graphic mode)

In this mode a color statement can offer “Illegal operate call” error message. Color statement can’t be utilized in this mode. however color range l is employed with line, circle etc. graphic statements to point out them in white color and color range zero is employed to show them in black color.

For example

SCREEN 2

CIRCLE (10,. 40), 50, 1 S A

The on top of program can draw circle with color one or white color.

SCREEN 7, 8, 9, 10

In these modes the format of the colour statement is as follows:

COLOR foreground color, background color

In these modes foreground color and therefore the background color will be specified individually. there’s no palette or the other restriction. the quantity of color {that can|which can|that may} be displayed will rely on the mode you’re in. These modes don’t permit show any screen border because it is feasible in SCREEN zero

Q.4: – Describe Palette statement.

Ans.: – PALETTE Statement
PALETTE statement is employed to pick out from one among 2 color sets that square measure already out there such these colours sets are going to be utilized by color parameter of LINE, CIRCLE, PSET and alternative graphics statements. PALETTE statement can work with EGA or VGA show systems. This statement won’t work with a CGA or Monochrome show.

Syntax:

PALETTE [attribute, color]

This statement works just for systems equipped with the improved Graphics Adapter (EGA). A GW-BASIC palette contains a group of colours, with every color specified by Associate in Nursing attribute. every attribute is paired with Associate in Nursing actual show color. This color determines the particular visual color on the screen, and depends on the setting of your screen mode and your actual physical. hardware show. PALETTE statement permits North American country to assign totally different color values to the various color range. as an example color range four that is red as default will be created inexperienced or blue or the other color. to alter color range four to blue, type as:

PALETTE 4, 1

This will create color four show color one. Any image or text on the screen exploitation color range four can flip blue. Any red color image that was on the screen before giving this command also will address blue color.‘ to line all the colour numbers to their default values, use PALETTE statement while not any parameters. the worth of palette is also either zero,

1. If palette zero or one, then the colours are:

Palette Numbers Color

0 zero Back ground color

0 one inexperienced

0 two Red

0 three Brown

1 zero Back ground color

1 one Cyan

1 two Magenta

1 three White

Q.5 Describe PSET statement.

Ans.: -PSET Statement
PSET Statement is employed within the graphic mode. This statement is employed to draw some extent at a given screen location throughout the employment of the graphic mode. Coordinates values will be on the far side the sting of the screen. However, values outside the number vary (-32768 to 32767) cause Associate in Nursing “Overflow” error. (0, O) is usually the higher left comer and (0, 199) is that the lower left comer in each high resolution and medium resolution. If the worth for the colour is bigger than three, Associate in Nursing “Illegal operate cal1” error is retuned.

Syntax:

PSET (x, y) [, Color]

Where x, y square measure the screen coordinates. the colour depends on the previous settings of the screen color, that is ex gratia.

Example

PSET (60, 30), 2

The on top of example plots one magenta purpose at row range sixty and column range thirty.

Program

10 CLS

20 FOR I=100 TO zero STEP -1

30 PSET (I, I), 0

40 NEXT T I

50 finish

The on top of program clears out the road by setting every constituent to zero.

Q.6 – Describe LINE statement.

Ans.: – LINE Statement
The Line statement will be accustomed draw lines or boxes on the screen. we will use the road statement to come up with a line between any 2 statements.

Syntax:

It has the subsequent general form:

LINE [(x1, y1)] (x2,-y2)‘[, [attribute] ‘[,B[F]][,style]]

The LINE statement is followed by 2 sets of numbers. The first combine in brackets is x1, square measure the co-ordinates of place to begin of the road and therefore the second combine within the brackets is x2, y2 square measure the co-ordinates of ending purpose of the road.

These 2 points‘ positions square measure separated by a minus or dash sign. The attribute specifies the colour or intensity of the show constituent. x1‘,yl and x2,y2 will be numeric constants or variables.

B (box) to draw a box with the points (x1, yl) and (x2, y2) at opposite corners. BF_(filled box) to draw a box as B and fills within the interior with points. the fashion may be a sixteen bit number mask used once swing down pixels on the screen.

This is known as line styling. vogue will one among O, 1, 2, 3, 4, and 5._ it’s used for traditional lines and boxes, however invalid for filled boxes.

The following statement would draw a -line on the medium resolution screen from the purpose (20, 60) to the purpose (200, 60)

LINE (20, 60) – (200, 60)

The following statement can draw a line from the last purpose to the 20″‘ column, 60″‘ row, and this is often the best variety of LINE statement.

LINE (20,60)

GW-BASIC permits you to draw lines, boxes and circles with the employment of the

LINE and CIRCLE commands. the subsequent statement can draw a sq. box up the higher left corner of the screen.

LINE (0, O)-(100, 175), , B

Program

10 CLS

20 SCREEN two

30 LINE (20, 10) (40,190)

40 LINE (30,170)

50 finish

Program

10 SCREEN one

20 COLOR zero,1

30 LINE (30,30) (210,140),1,B

40 finish

Q.7: make a case for CIRCLE statement with examples.

Ans.: – CIRCLE Statement
CIRCLE statement is employed to draw a circle, oval or Associate in Nursing arc on the screen throughout use of the graphic mode. Drawing straight lines and boxes is helpful, however having the ability to draw circles greatly extends our inventive vary. BASIC offers a really helpful CIRCLE statement. The reserved word CIRCLE instruction is employed to draw a circle.

Syntax:

CIRCLE (x, y), radius [, [color] [, [start], [end] [, aspect]]]

The (x, y) square measure the coordinate axis and coordinate axis coordinates of the middle of the circle or oval, and radius is that the radius of the circle or oval. The quantities x and y will be expressions. the colour specifies the colour of the circle or oval. Its price depends on the present screen mode. within the high resolution mode, zero indicates black and l indicates white.

The start and finish angle parameters square measure angular unit arguments between -2 and a pair of that specify wherever the drawing of the oval is to start and finish. The side describes the magnitude relation of the coordinate axis to the coordinate axis. The default ratio depends on the screen mode.

Ellipse may be a mathematical term used for shapes of oval sort by exploitation another parameter to the CIRCLE statement, oval will be drawn.

Example-1

10 SCREEN two

20 CIRCLE (320,100), 150

40 LINE (16835)-(472,165), ,B

50 END

Example-2

10 SCREEN two

20 CIRCLE (320,100), 150

30 LINE (220,55)-(420,145), ,B

40 END

Drawing Associate in Nursing oval

Program

10 CLS

20 SCREEN two

30 A CIRCLE (320, 100), 200,

40 END

The on top of program can draw Associate in Nursing oval.

Drawing Associate in Nursing Arc exploitation CIRCLE Statement two

A CIRCLE statement will be accustomed draw a part of a-circle or Associate in Nursing arc by together with 2 additional choices, al and a2.

Syntax

CIRCLE (X, Y) , Radius, al, a2,

When al Associate in Nursingd a2 square measure specified GW-BASIC attracts an arc exploitation these values as beginning and finish purpose of the arc. Al .and a2 square measure angle in angular unit. They specify wherever drawing of the oval -is to start and to finish. If any of those angle is negative, the oval is connected to the centre purpose with a line. GW-BASIC uses angular unit instead of the degree to live the angle. To convert a degree price to the angular unit, multiply the degree price with three.1415 and divide the result by a hundred and eighty as:

Radian =(Degree *3.1415)/180

Example

10 CLS

20 SCREEN two

30 KEY OFF

40 CIRCLE (100,l00),50,l,0,3;1415/2

50 END

OUTPUT

This will draw Associate in Nursing arc which is able to begin from zero angular unit positions and goes up to PI/2 or ninety degree position. the worth of PI=3. 14 1 5. once a negative range is employed to specify the al-and a2 price then the arc is drawn with the top purpose of the arc connection the centre of the circle. This position is helpful in creating charts.

.1: – Define graphic? Explain the modes of graphics?

Ans.: -Graphic

 

Q.8:- Describe DRAW statement.

Ans.:- DRAW Statement

The DRAW statement is used to draw. lines and other shapes on the screen. It is valid only in graphics mode. DRAW. Statement is used to a object of the shape other than circular. The object would be drawn as specified by a string containing drawing commands.

Syntax:

DRAW String

A string consists of single character command followed by a prefix that controls the size, direction etc. of the line and enclosed in the quotation marks.

Each of the following movement commands begins movement from the current graphics position. Movement commands move for a distance of scale factor *n, where the default or n is 1; thus, they move one point if n is omitted and the default scale factor is used.

Command            Moves

Un                           Up

Dn                        Down

Ln                          Left

Rn                         Right

En                         Diagonally up and right

Fn                         Diagonally down and right .

Gn                        Diagonally down and left

Hn                        Diagonally up and left

The following prefix commands may precede any of the above movement commands:

B          Move, but plot no points

N          Move, but return to original position when done

Example-1

Write down a program to draw a triangle.

Program

10 SCREEN 2

20 PSET (250, 50)

30 DRAW“G50 R100 H50”

40 END

Example-2

Write down a program to draw a Square

Program

10 SCREEN 2

20 PSET (250, 50)

30 DRAW“R5O D50 L50 U50”

40 E END

 

Short Questions

Q.1:- Define graphics

Ans.:-Graphics

Graphic is an art to design and produce pictorial representation of information. Graphics is displaying information on the screen.

Q.2:- On which bases graphics depends on?

Ans.:-Graphics depends on the hardware such as input, output and graphic card (CGA, VGA) .

Q.3:- What is meant by resolution of monitor?

Ans.:- Resolution

The number of pixels horizontally and vertically determines the resolution of your monitor

Q.4: -What is a pixel ? Can pixel be controlled?

Ans.: Pixel

Each specific coordinate is known as a pixel. For example the location of (230,100) will a pixel. Yes, the pixel can be controlled.

Q.5:-What are the modes of graphics?

Ans.:- Modes of Graphics

There are three modes of graphics, which are as follows:

  • Text mode
  • Medium resolution graphic mode
  • High resolution graphic mode.

Q.6:- What is the use of text mode?

Ans.:- Text Mode

Text mode is used for only textual data. In text based graphic, text, and lines can be drawn on the screen.

Q.7:- Write down the coordinates of text mode.

Ans.:- Coordinates of the Text Mode

In text mode the whole screen is divided into 80 column -and 25 rows. It has 16 colors out of any 2 colors palettes. Columns are counted from 0 to 39 or 79 and rows from 0 to 24.

Q.8:- What is the use of Medium-Resolution Graphic mode?

Ans.:- Medium-Resolution Graphic Mode

Medium-Resolution graphic mode is used in drawing graphic.

Q.9:- Write down the coordinates of Medium-Resolution Graphic mode.

Ans.:- Coordinates of the Medium-Resolution Graphic Mode

In medium resolution graphic mode the display screen is divided into a matrix consisting of 320 columns and 200 rows of pixels. Thus the position of each and every pixel will be determined by its coordinates on x-axis and y-axis of the screen.

Q.10:- What is the use of High-Resolution Graphic mode?

Ans.:- High-Resolution Graphic Mode

High-Resolution graphic mode is used in drawing graphics.

Q.11:- Write down the coordinates of High-Resolution Graphic mode.

Ans.:- Coordinates of the High-Resolution Graphic Mode

In high resolution graphic mode the display screen is divided into a matrix consisting of 640*20O pixels. We are able to display the text characters in 25 lines of 80 characters in each line.

_Q.12:- What is the use of SCREEN Statement?

Ans.:- SCREEN Statement .

The SCREEN statement is commonly used to select a screen mode appropriate for a particular display hardware configuration.

Q.13:- What is the use of SCREEN 0 Statement?

Ans.:- SCREEN 0 Statement

SCREEN 0 statement is used for text mode. Text mode is the default mode. You can do only textual work in text mode. This mode is not used in graphics.

Q.14:- What is the use of SCREEN 1 Statement?

Ans.:- SCREEN 1 Statement

SCREEN l statement is used for medium-resolution graphic mode. This statement activates the graphics mode. ‘ ~

Q.15:- What is the use of SCREEN 2 Statement?

Ans.:- SCREEN 2 Statement

C SCREEN 2 statement is used for high-resolution graphic mode.

Q.16:-, What is the use of COLOR Statement?

Ans.:- COLOR Statement .

COLOR statement is used to select display colors in graphic modes.

Q.17:- What is the use of PALETTE Statement?

Ans.:- PALETTE Statement

It is used to select from one of two colors sets that are already available such that these colors sets will be used by color parameter of a LINE, CIRCLE, PSET, DRAW or other graphics utilities I

Q.18:- Define LINE statement

Ans.:- LINE statement

The purpose of the line statement is to draw lines and boxes on the screen.’ We can use line statement to generate a line between any two statements.

Q.19:-What is the use of CIRCLE statement?

Ans.: CIRCLE statement

The purpose of the CIRCLE statement is to draw a circle, ellipse on the screen during use of the graphic mode.

Q.20:-What is the use of PSET statement?

Ans.:- PSET statement

PSET statement is used to display a point at a specified place on the screen during use of the graphics mode.

Q.21:- What is the use of DRAW Statement?

Ans.:- DRAW Statement

The DRAW statement is used to draw lines and other shapes on the screen. It is valid only in graphics mode. DRAW statement is used to an object of the shape other than circular. The object would be drawn as specified by a  string containing drawing commands.

Please follow and like us:
error