Implementation of Line Incremental Algorithm
#include<graphics.h>
#include<iostream.h>
#include<conio.h>
void main()
{
int px1, px2, py1, py2, b;
float m;
int dy, dx;
cout<<"Dear please enter P1 points to draw a line";
cin>>px1>>py1;
cout<<"Dear please enter P2 points to draw a line";
cin>>px2>>py2;
dy=py2-py1; //py1-py2;
dx=px2-px1; //px1-px2;
m=float(dy/dx);
b=py1-m*px1;
//b=py2-m*px2;
int gd=DETECT, gm;
initgraph(&gd, &gm,"..\\bgi");
if(m==1)
{
for(;px1<=px2;px1++)
{
putpixel(px1,py1, WHITE);
py1++;
}
}
else
{
if(m<1)
{
for(;px1<=px2;)
{
putpixel(px1, py1, GREEN);
px1++;
py1=m*px1+b;
}
}
else
{
for(;py1<=py2;)
{
putpixel(px1, py1, RED);
py1++;
px1=(py1-b)/m;
}
}
}
getch();
}
No comments:
Post a Comment