0% found this document useful (0 votes)
7 views2 pages

CG Thin

Uploaded by

yenoj36493
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

CG Thin

Uploaded by

yenoj36493
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

NAME: SARA RAWAT

ROLL.NO: SEB239

Title: Bresenham's Line Algorithm (THIN LINE)

Descrip on: Program to draw a Thin Line using Bresenham's Line Drawing Algorithm

#include<stdio.h>

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h> int

main(void)

/* request auto detec on */

int gdriver = DETECT, gmode; int

i,x,y,x1,y1,x2,y2,dx,dy,length,P0;

/* ini alize graphics and local variables */

prin ("Enter the star ng coordinates of line");

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

prin ("Enter the ending coordinates of line");

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

initgraph(&gdriver, &gmode, "");

dx=abs(x2-x1);

dy=abs(y2-y1);

if(dx>dy)

length=dx;

else

length=dy;

putpixel(x1,y1,2);

x=x1;

y=y1;
P0=2*dy-dx;

for(i=1;i<=length;i++)

if(P0<0)

x=x+1;

y=y+0;

putpixel(x,y,2);

P0=P0+2*dy;

else

x=x+1;

y=y+1;

putpixel(x,y,2);

P0=P0+2*dy-2*dx;

/* clean up */

getch();

closegraph();

return 0;

You might also like