Normal you can draw line using line function. But in these Bresenhams without using line function. It will draw the line. it will draw the line using the pixel coordinates by thorough increasing down and right direction of the pixel in the centers to the integer coordinates. See

#include”stdio.h”

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

{

int gd=DETECT,gm,x,y,x1,x2,x3,y1,y2,y3,p,i;

clrscr();

initgraph(&gd,&gm,"quot;"quot;);

gotoxy(12,2);

printf("quot;Line Breshams algorithm\n"quot;);

gotoxy(12,3);

printf("quot;----------------------------------------"quot;);

printf("quot;\nenter the left co ordinates\n"quot;);

printf("quot;x1="quot;);

scanf("quot;%d"quot;,&x1);

printf("quot;\ny1= "quot;);

scanf("quot;%d"quot;,&y1);

printf("quot;Enter the right co ordinates\n"quot;);

printf("quot;x2= "quot;);

scanf("quot;%d"quot;,&x2);

printf("quot;\ny2= "quot;);

scanf("quot;%d"quot;,&y2);

if(x1>x2)

{

x=x2;

y=y2;

x3=x1-x2;

y3=y1-y2;

}

else

{

x=x1;

y=y1;

x3=x2-x1;

y3=y2-y1;

}

p=2*y3-x3;

cleardevice();

putpixel(x,y,1);

for(i=0;i<=x3;i++)

{

if(p<0)

{

x++;

p=p+2+y3;

}

else

{

x++;

y++;

p=p+2*(y3-x3);

}

putpixel(x,y,1);

}

getch();

gotoxy(12,2);

printf("quot;\nACTUAL LINE"quot;);

gotoxy(12,3);

printf("quot;\n--------------------------------------"quot;);

getch();

}

Line Bresehams Algorithm

Enter the left co-ordinates

X1 = 100

Y1 = 100

Enter the right co-ordinates

X2 =200

Y2=200

ACTUAL LINE

**SOURCE CODE**#include”stdio.h”

### Source code | programming

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

{

int gd=DETECT,gm,x,y,x1,x2,x3,y1,y2,y3,p,i;

clrscr();

initgraph(&gd,&gm,"quot;"quot;);

gotoxy(12,2);

printf("quot;Line Breshams algorithm\n"quot;);

gotoxy(12,3);

printf("quot;----------------------------------------"quot;);

printf("quot;\nenter the left co ordinates\n"quot;);

printf("quot;x1="quot;);

scanf("quot;%d"quot;,&x1);

printf("quot;\ny1= "quot;);

scanf("quot;%d"quot;,&y1);

printf("quot;Enter the right co ordinates\n"quot;);

printf("quot;x2= "quot;);

scanf("quot;%d"quot;,&x2);

printf("quot;\ny2= "quot;);

scanf("quot;%d"quot;,&y2);

if(x1>x2)

{

x=x2;

y=y2;

x3=x1-x2;

y3=y1-y2;

}

else

{

x=x1;

y=y1;

x3=x2-x1;

y3=y2-y1;

}

p=2*y3-x3;

cleardevice();

putpixel(x,y,1);

for(i=0;i<=x3;i++)

{

if(p<0)

{

x++;

p=p+2+y3;

}

else

{

x++;

y++;

p=p+2*(y3-x3);

}

putpixel(x,y,1);

}

getch();

gotoxy(12,2);

printf("quot;\nACTUAL LINE"quot;);

gotoxy(12,3);

printf("quot;\n--------------------------------------"quot;);

getch();

}

**OUTPUT**

Line Bresehams Algorithm

Enter the left co-ordinates

X1 = 100

Y1 = 100

Enter the right co-ordinates

X2 =200

Y2=200

ACTUAL LINE

## No comments:

Write comments