#include<iostream.h>
#include <dos.h>
#include<conio.h>
#include <graphics.h>
#include<stdlib.h>
void lineBres(int xa, int ya, int xb, int yb)
{
int dx = abs(xb - xa), dy =abs(yb - ya);
int twodx = 2 * dy - dx;
int twody = 2 * dy;
int p = 2 * (dy - dx);
putpixel(xa, ya, RED);
while (xa < xb)
{
xa++;
if (twodx < 0)
twodx +=twody;
else
{
ya++;
twodx +=p;
}
putpixel(xa, ya, RED);
delay(20);
}
}
void main()
{
int a,b,c,d;
int gd = DETECT, gm;
initgraph(&gd, &gm, "c:\\tc\\bgi");
cout<<"\n\t\tBresenham's Line Drawing Algorithm";
cout<<"\n\t\t**********************************";
cout<<"\n\tEnter following coordinates for a line";
cout<<"\n\txa=";
cin>>a;
cout<<"\tya=";
cin>>b;
cout<<"\txb=";
cin>>c;
cout<<"\tyb=";
cin>>d;
lineBres(a,b,c,d);
getch();
}
#include <dos.h>
#include<conio.h>
#include <graphics.h>
#include<stdlib.h>
void lineBres(int xa, int ya, int xb, int yb)
{
int dx = abs(xb - xa), dy =abs(yb - ya);
int twodx = 2 * dy - dx;
int twody = 2 * dy;
int p = 2 * (dy - dx);
putpixel(xa, ya, RED);
while (xa < xb)
{
xa++;
if (twodx < 0)
twodx +=twody;
else
{
ya++;
twodx +=p;
}
putpixel(xa, ya, RED);
delay(20);
}
}
void main()
{
int a,b,c,d;
int gd = DETECT, gm;
initgraph(&gd, &gm, "c:\\tc\\bgi");
cout<<"\n\t\tBresenham's Line Drawing Algorithm";
cout<<"\n\t\t**********************************";
cout<<"\n\tEnter following coordinates for a line";
cout<<"\n\txa=";
cin>>a;
cout<<"\tya=";
cin>>b;
cout<<"\txb=";
cin>>c;
cout<<"\tyb=";
cin>>d;
lineBres(a,b,c,d);
getch();
}
No comments:
Post a Comment
Thank you for using this blog.