0 votes
104 views
in Computer Graphics by (98.9k points)
retagged by
Write a C program To implement Bresenham's Line Drawing Algorithm

1 Answer

0 votes
by (98.9k points)
selected by
 
Best answer
#include<stdio.h>
#include<graphics.h>
#include<math.h>
#include<conio.h>
void main()
{
float x,y,x1,y1,x2,y2,dx,dy,e;
int i,gd,gm;
clrscr(); 
printf("Enter the value of x1 :\t");
scanf("%f",&x1);
printf("Enter the value of y1 :\t");
scanf("%f",&y1);
printf("Enter the value of x2 :\t");
scanf("%f",&x2);
printf("Enter the value of y2 :\t");
scanf("%f",&y2); 
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\tc\\BGI");

dx=abs(x2-x1);
dy=abs(y2-y1); 
x = x1;
y = y1;
putpixel (x, y, 15) ;
 
e = 2 * dy-dx;

i = 1; 
do
{
while(e >= 0)
{
y = y + 1;
e = e - 2 * dx;
}
x = x + 1;
e = e + 2 * dy;
i = i + 1;
putpixel (x, y, 15);
}
while( i <= dx);
getch();
closegraph();
}
asked Apr 30, 2023 in Computer Graphics by (98.9k points)
retagged Nov 4, 2023 by
Write A program To implement Cohen sutherland Line Clipping Algorithm

Related questions

0 votes
1 answer 81 views
0 votes
1 answer 92 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

...