Friday, 29 June 2012

IMPLEMENTATION OF BRESENHAM’S LINE DRAWING

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
            int gd=DETECT,gm;
            int x0,y0,x1,y1,dx,dy,p0,s,t,color;
            clrscr();
            printf("Enter the starting coordinates(x0,y0):\n");
            scanf("%d%d",&x0,&y0);
            printf("Enter the ending coordinates(x1,y1):\n");
            scanf("%d%d",&x1,&y1);
            printf("Enter integer to select color:");
            scanf("%d",&color);

            initgraph(&gd,&gm,"C:/BC/BGI");
            if(x1<x0)
            {
             t=x0;x0=x1;x1=t;
             t=y0;y0=y1;y1=t;
            }         
            dx=x1-x0;
            dy=y1-y0;
            p0=(2*dy)-dx;

            putpixel(x0,y0,color);
            color=color+10;
            while(x0<x1)
            {
               if(p0<0)
              {
                x0=x0+1;
                p0=p0+(2*dy);
              }
              else
              {
               x0=x0+1;
               y0=y0+1;
              p0=p0+(2*dy)-(2*dx);
            }
             putpixel(x0,y0,color);
             color=color+10;
            }
            getch();
}

OUTPUT:
Enter the starting coordinates(x0,y0):0 0
Enter the ending coordinates(x1,y1):100 100
Enter integer to select color:6
           


No comments:

Post a Comment