Wednesday, 9 November 2011

BRESENHAM'S LINE DRAWING PROGRAM IN C

 BRESENHAM'S LINE DRAWING PROGRAM IN C

Similar Programs



/* 1<=m<infinity */

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

void linebres(int xa,int ya,int xb,int yb);
void main()
{
   int gd=DETECT,gm,xa,ya,xb,yb;
   initgraph(&gd,&gm,"c:\\tc\\bgi");
   printf("Enter the first cordinates:");
   scanf("%d%d",&xa,&ya);
   printf("Enter the last cordinates:");
   scanf("%d%d",&xb,&yb);
   linebres(xa,ya,xb,yb);
   getch();

}

void linebres(int xa,int ya,int xb,int yb)
{
   int dx=xb-xa,dy=yb-ya,n;
   int p=2*dx-dy;
   int p1=2*dx;
   int p2=2*(dx-dy);
   int x,y,yend;
   if(ya>yb)
   {
      x=xb;
      y=yb;
      yend=ya;
    }
    else
    {
      x=xa;
      y=ya;
      yend=yb;
    }
    putpixel(x,y,n);
    while(y<yend)
    {
       y++;
       if(p<0)
       p+=p1;
       else
       {
        x++;
        p+=p2;
       }
       putpixel(x,y,3);
      //putpixel(x+3,y,5);
    }
}

0 comments:

Post a Comment

 

Copyright @ 2013 Appychip.

Designed by Appychip & YouTube Channel