0 votes
80 views
in Computer Graphics by (98.9k points)
edited by
Bresenham's Line drawing Algorithm

1 Answer

0 votes
by (98.9k points)
selected by
 
Best answer
# include <stdio.h>

# include <conio.h>

# include <graphics.h>

void main()

{

int dx,dy,x,y,p,x1,y1,x2,y2;

int gd,gm;

clrscr();

printf("\n\n\tEnter the co-ordinates of first point : ");

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

printf("\n\n\tEnter the co-ordinates of second point : ");

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

dx = (x2 - x1);

dy = (y2 - y1);

p = 2 * (dy) - (dx);

x = x1;

y = y1;

detectgraph(&gd,&gm);

initgraph(&gd,&gm,"c:\tc2\bgi");

putpixel(x,y,WHITE);

while(x <= x2)

{

if(p < 0)

{

x=x+1;

y=y;

p = p + 2 * (dy);

}

else

{

x=x+1;

y=y+1;

p = p + 2 * (dy - dx);

}

putpixel(x,y,WHITE);

}

getch();

closegraph();

}

Related questions

0 votes
1 answer 104 views
0 votes
1 answer 105 views
0 votes
1 answer 64 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

557 users

...