Program 4-Write A Program in CPP For Bresenham's Line Drawing Algorithm. Name-Aashish Pandey Date-04/03/2024 Source Code

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Program 4-Write a program In CPP for Bresenham’s Line drawing algorithm.

Name-Aashish Pandey Date-04/03/2024

Source Code-
#include <graphics.h>
#include <dos.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
void Bresenham(int xa, int ya, int xb, int yb)
{
int dx = abs(xa - xb), dy = abs(ya - yb);
int p = 2*dy - dx;
int twoDy = 2*dy, twoDyDx = 2*(dy - dx);
int x, y, xEnd;
if(xa>xb){
x = xb;
y = yb;
xEnd = xa;
}
else{
x = xa; y = ya ; xEnd = xb; Output-
}
putpixel(x, y, WHITE);
while(x < xEnd){
x++;
if(p<0){
p = p + twoDy;
}
else{
y++;
p = p + twoDyDx;
}
putpixel(x,y,WHITE);
}
}
int main()
{
int gd=DETECT, gm, err;
initgraph(&gd, &gm, "C:\\TC\\BGI");
err = graphresult();
if(err!=grOk){
printf(" error: %s\n", grapherrormsg(err));
}
Bresenham(1099, 45, 200, 110);
getch();
return 0;
}

You might also like