Steps to write graphics program


Steps to be followed

Following steps should be followed while writing graphics program.

Note : Graphics will work only on windows Xp or windows 98...
or you should install Dos-box or can use Dev C++ compiler.
But XP is recommended as it will not give you any problems.

Step 1 :

Include 'graphics.h' header file.

Step 2 :

Declare two integer variables---one for driver and one for mode.

example: int d,m;

Step 3 :

Write the following statement :-

d=DETECT; //Auto detection for driver

where d= integer representing driver.

D=DETECT---with this statement, the compiler set the graphics mode to the highest resolution.

Step 4 :

use initgraph() function like :

initgraph(&d,&m,"c:\\turboc3\\bgi");

Step 5 :

Use the functions you want to use for example circle(),ellipse() etc...

Step 6:

Close the graphics with closegraph() function.



Note : Graphics will work only on windows Xp or windows 98...

Example :

//Program to draw an ellipse

#include <stdio.h>
#include <conio.h>
#include <graphics.h>

void main()
{

int d,m;

int sangle=0,endangle=360,xradius=40,yradius=200;

int midx,midy;

d=DETECT;

initgraph(&d,&m,"c:\\turboc3\\bgi");

midx=getmaxx()/2;

midy=getmaxy()/2;

ellipse(midx,midy,sangle,endangle,xradius,yradius);

getch();

closegraph;

}


Description :

Same steps are followed as described above.

First we have included the graphics.h header file.

Second in the main method, we have declared two integer variables :

int d,m;

where d--represents driver
m---represents mode

Next we have declared and initialize the required variables as sangle=0 & others.

Next we have written d=DETECT

Next we initialize the graphics with the help of initgraph() functions. It takes the three parameters:

1. address of graphics driver so we used '&d' as first argument since '&' represents the address.

2. address of graphics mode so we used '&m' as second argument.

3. The path of to graphics

Next we used the getmaxx,getmaxy methods to calculate the centre position. And then we have use ellipse() function to draw the ellipse.

Next we have closed the graphics with closegraph() method.

0 comments:

Post a Comment