You are on page 1of 25

Graphics

Ahmed Ali Qureshi

There are 2 modes


Text mode  Graphics mode  In text mode it is possible to display or capture only text in termsof ASCII  In graphics ode any type of figure can be displayed, captured and animated.


Include
Graphics.h  Graphics.lib


Graphics.h


This file contains definitions and explanation of all the graphic functions and constants

Graphics.lib


This file contains standard graphic functions

Example
           

#include<iostream.h> #include<conio.h> Void main() { Clrscr(); Int gd=detect,gm; Initgraph(&gd, &gm, c:\tc\bgi); c:\tc\ Criclr(330, 180, 100); Closegraph(); Getch(); Restorecrtmode(); }

Explanation
     

Initgraph: This functions initialises the graphic mode. it selects the best resolution and direct that value to mode in variable gm. The two int varialbes, gd and gm are graphic driver and graphic mode respectively. The gm handles value that tells us which resolution an dmontor we are using. The dg specifies the graphic driver to be used.

gd=DETECT


It means we have passed the highest possible value available for the detected driver. The & symbol is used for initgraph to pass address of the constants.

Path (C:\tc\bgi) (C:\tc\




It specifies the directory path where initgraph looks for graphics drivers (*.BGI) first. If files are not there then initgraph will look for the current directory of the program. If it is unable to find within current working directory then will parse an error. One can leave it blank ( ) if the *.BGI files are within the working directory.

Circle()


Circle function takes X and Y values with respect to top left corner fo the screen and third coordinate is radius.

Closegraph();


It switches back the screen from graphics mode to text mode. If you dont use this function then you may have undesirable effects.

Getch()


This function gets a character from console but does not echo it on screen.

Rectangle(left,top,right,bottom)


It drawsa rectangle with (left,top) as upper let of the rectanble & (right,bottom) as its lower right of the corner.

Ellipse(x,y,endangle,xrad,yrad) Ellipse(x,y,endangle,xrad,yrad)


It draws an elliptical arc. Here (x,y) ar ethe (x,y) cooridnatres of center of the ellipse. (stagle,endangle) are the starting and ending stagle,endangle) angles. If stangle=0 and endanle=360 then this function stangle=0 endanle=360 draws complete ellipse.

Arc(x,y,stangle,endangle,rad)
 

It draws circular arc of the given color. (x,y) are the center point of the arc and arc travels from stangle to endangle. (rad) defines the radius of the arc.

Line(x1,y1,x2,y2)


It draws a line between two specified points (x,y) towards (2,y2). This functions comes handy if you want to draw box like shapes or just plotting the graphs etc.

Setlinestyle(style,x,y) etlinestyle(style,x,y)


It specifies the type of line, patern and the thickness that is going to appear on the screen. Options like solid, dotten, centered, dashed.

Putpixel(x,y,color)
 

It is used to put a piexel at specified points (x,y) It comes handy when we have to plot a point of specified color at desired location. (color) can be defined in function as white or BLUE or specify the color code.

Bar(left,top,right,bottom)


It draws the filled-in, rectangular two filleddimensional bar. It is filled suing the fill pattern and fill color Use F1 to find about fill pattern and fill color.

Color palettes
 

The grahics.h has declartion about 16 colors. In order to use the color in program use
Setcolor()  Setbkcolor()  Setfillstyle()


Setcolor()


It sets the value of current drawing color to color as you put in the brackets.

Setbkcolor()


It sets the value of backgrou color which by default is black.

Setfillstyle()


It sets the current fill pattern and fill color.

Restorecrtmode()


This mode will restore the original video mode detected by initgraph function.

Values of Colors in Graphics.h

You might also like