Translate

Tuesday, May 26, 2020

Bresenhanse Line Darwing Algorithm

Bresenhanse Line Darwing Algorithm 

Aim: Write a program line using  Bresenhanse Line Darwing Algorithm.

Source Code:

#include<graphics.h>
#include<iostream.h>
#include<conio.h>
#include<math.h>
void bre(int x1,int x2,int y1,int y2);
void main()
{
int x1,y1,x2,y2;
initgraph(&gd,&gm,"C//TURBOC3//BGI");
cleardevice();
//step1
cout<<"Bresenhanse Line Darwing Algorithm";
cout<<"/n Enter a starting co-ordinate of a line";
cin>>x1>>y1;
cout<<"/n Enter a ending co-ordinate of a line";
cin>>x2>>y2;
bre(x1,y1,x2,y2);
getcha();
closegraph();
}
void bre(int x1,int y1,int x2)
{
int x,y,dx,dy,sx,sy,len,temp,flag,pk,i;
//step 2
x=x1;
y=y1;
dx=abs(x2-x1);
dy=abs(y2-y1);
if((x2-x1)>0)
{
sx=1;
}
else
{
sx=-1;
}
if((y2-y1)>0)
{
sy=1;
}
else
{
sy=-1;
}
//step 3
if(dy>dx)
{
len=dy;
temp=dx;
dx=dy;
dy=temp;
flag=1;
}
else
{
len=dx;
flag=0;
}
//step 4
Pk=2*dy-dx;
putpixel(x,y,WHITE);
//step 5
for(i=1;i<=len;i++)
{
white(pk>0)
{
if(flag==1)
{
x=x+sx;
}
else
y=y+sy;
}
pk=pk-2*dx;
}
if(flag==1)
{
y=y+sy;
}
else
{
x=x+sx;
}
pk=pk+2*dy;
putpixle(x,y,WHITE);
}
}

YOUTUBE LINK: https://www.youtube.com/watch?v=p8FVwgSl7lo










No comments:

Post a Comment

Bresenhanse Line Darwing Algorithm