Search & Find out

Thursday, December 3, 2009

bresenham line drawing Program


#include "stdio.h"
#include "conio.h"
#include "graphics.h"
#include "math.h"
void brs (int x1,int y1,int x2,int y2)
{
    int delx,dely,x,y,e,i;
    if (x1==x2 && y1==y2)
    {
        printf ("The line cannot be drawn");
        return;
    }
    else
    {
        delx = abs (x2-x1);
        dely = abs (y2-y1);
        x = x1;
        y = y1;
        e = 2 * dely - delx;
        i = 1;
    }
    abc:
    putpixel (x,y,15);
    while (e >= 0)
    {
        y = y + 1;
        e = e - 2 * delx;
    }
    x = x + 1;
    e = e + 2 * dely;
    i = i + 1;
    if (i <= delx)
    {
        goto abc;
    }
}
void main ()
{
    int gd,gm;
    int x1,y1,x2,y2;
    clrscr ();
    printf ("Enter the starting points: ");
    scanf ("%d%d",&x1,&y1);
    printf ("Enter the ending points:");
    scanf ("%d%d",&x2,&y2);
    detectgraph (&gd,&gm);
    initgraph (&gd,&gm,"c:\\TC\\BGI");
    brs (x1,y1,x2,y2);
getch ();
closegraph ();
}



Download the executable (.exe)  file for this program..
download

0 comments:

Post a Comment

 

My Blog List

Term of Use

Copyright © 2009 Black Nero is Designed by Ipietoon Sponsored by Online Business Journal