#include<stdio.h> #include<graphics.h> #include<math.h> void lineBresen(float x1,float y1,float x2,float y2) { int dx=abs(x2-x1),dy=abs(y2-y1),p,i=1; float x,y; if(x1<=x2) { x=x1; y=y1; } else { y=y2; x=x2; } p=((2*dy)-dx); putpixel(x,y,RED); while(i<=dx) { delay(100); x++; if(p<0) { p=p+(2*dy); } else { y++; p=p+(2*(dy-dx)); } putpixel(x,y,RED); i++; } } int main() { float x1,y1,x2,y2; int i,gd,gm; clrscr(); /* Initialise graphics mode ---------------------------------- */ detectgraph(&gd,&gm); initgraph(&gd,&gm,"C://TurboC3//BGI"); /* Read two end points of line ---------------------------------- */ 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); lineBresen(x1,y1,x2,y2); getch(); closegraph(); return 0; }
Bresenham line drwaing algorithm program in c
Subscribe to:
Posts (Atom)
No comments:
Post a Comment