Search & Find out

Thursday, December 3, 2009

line drawing Program



#include "stdio.h"
#include "conio.h"
#include "graphics.h"

void main()
{
int  gd,gm,x,x1,x2,y,y1,y2,ax,ay,dx,dy,l,i,a[1000],b[1000];
float bx,by;

detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\tc\\bgi");
printf("Welcome to Line Drawing program \n\n");

printf("Enter the starting & ending points of x & y \n");
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
clrscr();

if(x1>x2)
{
  x=x2;
  dx=x1;
}
else
{
  x=x1;
  dx=x2;
}

if(y1>y2)
{
  y=y2;
  dy=y1;
}
else
{
  y=y1;
  dy=y2;
}

ax=dx-x;
ay=dy-y;
bx=1;
by=1;

if(ax>ay)
{
 by=ay/ax;
 }
 else if(ax
 {
 bx=ax/ay;
 }

 if(ax
 {
 l=ax;
 }
 else
 {
 l=ay;
 }

 for(i=1;i<=l;i++)
 {
   a[i]=x+bx;
   x=a[i];

   b[i]=y+by;
   y=b[i];
  }

  putpixel(x1,y1,1);

  for(i=1;i<=l;i++)
  {
    putpixel(a[i],b[i],1);
  }

getch();
closegraph();
}


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




0 comments:

Post a Comment

 

My Blog List

Term of Use