LINE DRAWING ALGORITHM

62
rate or flag this page

By sasikala


Source code with sample output

Aim :

To draw a line using line drawing algorithm in c (or)

Write a c program to implement line drawing algorithm.

 

 

#include<stdio.h>

#include<graphics.h>

#include<math.h>

void main()

{

float x,y,x1,y1,x2,y2,dx,dy,e;

int i,gd,gm;

clrscr();

printf("\n Enter the value of x1:\t");

scanf("%f",&x1);

printf("\n Enter the value of y1:\t");

scanf("%f",&y1);

printf("\n Enter the value of x2:\t");

scanf("%f",&x2);

printf("\n Enter the value of y2:\t");

scanf("%f",&y2);

detectgraph(&gd,&gm);

initgraph(&gd,&gm,"c:\\Tc\\BGI");

dx=abs(x2-x1);

dy=abs(y2-y1);

//

x=x1;

y=y1;

//

e=2*dy-dx;

i=1;

do

{

putpixel(x,y,15);

while(e>=0)

{

y=y+1;

e=e-2*dx;

}

x=x+1;

e=e+2*dy;

i=i+1;

}

while(i<=dx);

getch();

closegraph();

}

OUTPUT:

Enter the value of x1: 50

Enter the value of y1: 100

Enter the value of x2: 150

Enter the value of y2: 200

Print   —   Rate it:  up  down  flag this hub

Comments

RSS for comments on this Hub

No comments yet.

Submit a Comment

Members and Guests

Sign in or sign up and post using a hubpages account.


optional


  • No HTML is allowed in comments, but URLs will be hyperlinked
  • Comments are not for promoting your hubs or other sites

working