Graphics Program
Graphics Program
ii. Create New Project "DialogBox" will appear select "empty project"
and name your project in the space provided. Select Language
Press OK, you are now able to use graphics.h functions in your code.
STEP 5: Testing sample Program
In new versions of dev c++ compiler automatically adds one source file to
project. If there is no any existing source file simply add new file By
chossing new file option from file menu. Type the following code and
save the file. I saved file as "main.cpp" its your chooice whatever you
name it.
#include<graphics.h>
int main( ){
initwindow( 700 , 700 , "MY First Program");
circle(200, 200, 150);
getch();
return 0;
}
view rawexample_1_bgi hosted with ❤ by GitHub
#include<graphics.h>
#include<isotream.h>
int main() {
rectangle(100,100,200,200);
getch();
closegraph();
return 0;
}
1. DDA(Digital Differential Analyzer ) Algorithm
#include <graphics.h>
#include <iostream.h>
#include <math.h>
#include <dos.h>
void main( )
{
float x,y,x1,y1,x2,y2,dx,dy,step;
int i,gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx>=dy)
step=dx;
else
step=dy;
dx=dx/step;
dy=dy/step;
x=x1;
y=y1;
i=1;
while(i<=step)
{
putpixel(x,y,5);
x=x+dx;
y=y+dy;
i=i+1;
delay(100);
}
closegraph();
}
2. Bresenham’s Line drawing algorithm
#include<iostream.h>
#include<graphics.h>
dx=x1-x0;
dy=y1-y0;
x=x0;
y=y0;
p=2*dy-dx;
while(x<x1)
{
if(p>=0)
{
putpixel(x,y,7);
y=y+1;
p=p+2*dy-2*dx;
}
else
{
putpixel(x,y,7);
p=p+2*dy;
}
x=x+1;
}
}
int main()
{
int gdriver=DETECT, gmode, error, x0, y0, x1, y1;
initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
return 0; }