0% found this document useful (0 votes)
4 views1 page

Lab 3 Bresenhams

This C program uses the graphics library to draw a line between two points specified by the user. It implements Bresenham's line algorithm to determine which pixels to illuminate on the screen. The program initializes the graphics mode, takes user input for coordinates, and then plots the line accordingly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Lab 3 Bresenhams

This C program uses the graphics library to draw a line between two points specified by the user. It implements Bresenham's line algorithm to determine which pixels to illuminate on the screen. The program initializes the graphics mode, takes user input for coordinates, and then plots the line accordingly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include<stdio.

h>
#include<conio.h>
#include<graphics.h>

void main() {
int x, y, x1, y1, x2, y2, p, dx, dy;
int gd = DETECT, gm;

printf("\nEnter the x-coordinate of the first point ::");


scanf("%d", &x1);
printf("\nEnter the y-coordinate of the first point ::");
scanf("%d", &y1);
printf("\nEnter the x-coordinate of the second point ::");
scanf("%d", &x2);
printf("\nEnter the y-coordinate of the second point ::");
scanf("%d", &y2);

x = x1;
y = y1;
dx = x2 - x1;
dy = y2 - y1;

initgraph(&gd, &gm, "C:\\TurboC3\\BGI");


putpixel(x, y, x);

p = 2 * dy - dx;

while (x <= x2) {


if (p < 0) {
x = x + 1;
p = p + 2 * dy;
} else {
x = x + 1;
y = y + 1;
p = p + 2 * dy - 2 * dx;
}
putpixel(x, y, x);
}

getch();
closegraph();
}

You might also like