Wednesday, September 1, 2010

GRAPHICS

GRAPHICS

For drawing any graphics on the screen we need a header file
For switching over to graphic mode that offers best solution function ‘initgraph()’ must be used.

Syntax:
initgraph(int *gdriver, int *gmode, char *path-to-driver);
gdriver=DETECT causes the ‘initgraph()’ to load the appropriate bgi file, it then sets the value of gdriver and gmode. If DETECT is not used we have to load appropriate values of gmode and gdriver.
Cursor is not displayed in the graphics mode.
The range of x-axis anf y-axis depends upon the resolution of adaptor.For Bgi, it is 40X480
Function Working
1.outtextxy(x,y,string) display a string at location (x,y)
Eg.
#include
#include
#include
void main()
{
int gdriver,gmode;
gdriver=DETECT;
initgraph(&gdriver,&gmode,”c:\\tc\\bgi”);
outtext(320,240,”Kantipur city college”);
getch();
}
2.putpixel(x,y,color) lists the pixel at (x,y) in the desired color (1-15)
1—black
15---white
3.line(x1,y1,x2,y2) draw a line from (x1,y1) to (x2,y2)
4.circle(x,y,rad) draws a circle with center (x,y) and radius rad
5.rectangle(x1,y1,x2,y2) draws a rectangle whose end coordinates are (x1,y1,x2,y2)
6.ellipse(x,y,start,end,xrad,yrad) draws an ellipse with (x,y ) as center and xrad and yrad as the ‘x’ and ‘y’ radius. If start is 0 and end is 180 only upper half of the ellipse is drawn.
7. arc(x,y,start,end,rad) Draws an arc with (x,y) as center,rad as radius ,start and end as the starting and ending angles.
8.bar(x1,y1,x2,y2) draws a filled rectangular pattern and color.
9.settextstyle(font,dir,size) dir specifies the direction 0-horizontal,1-vertical ,size(1-4),font may also take integer value.
10.setlinestyle(type,pattern,thickness) type specifies the type of line to draw 0-solidline,1-dotted line etc.
11.setfillstyle(pattern,color) sets the pattern and color that can be used to fill closed figures. Pattern take values (0-12) where 1 for solid fill. Colors may also be specified with integer.
12.floodfill(x,y,color) fills a desired region,if (x,y) lies within the region. The exterior will be filled if (x,y) lies outside the region.
13.setcolor(color) sets the current drawing color. The color may either be specified woth name or corresponding integer value.

No comments:

Post a Comment