P. 1
Grpahics c++

Grpahics c++

|Views: 24|Likes:
Published by Muhammad Ali

More info:

Published by: Muhammad Ali on Jun 16, 2011
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PPT, PDF, TXT or read online from Scribd
See more
See less






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.  

Graphics.h  Graphics.lib 


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


This file contains standard graphic functions


#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(); }


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.


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 function takes X and Y values with respect to top left corner fo the screen and third coordinate is radius.


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


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


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.


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.


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.


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.


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() 


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


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


It sets the current fill pattern and fill color.


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

Values of Colors in Graphics.h

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->