0% found this document useful (0 votes)
22 views6 pages

Program To Draw Lines in Given Co-Ordinates Using DDA Algorithm

This program uses the DDA (Digital Differential Analyzer) algorithm to draw lines between points specified by (x1, y1) and (x2, y2) coordinates. It initializes the graphics mode, gets the coordinate inputs, calculates the slope and step increments between points, and uses a while loop to incrementally draw pixels between the points using the putpixel() function.

Uploaded by

Sunny Mishra
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views6 pages

Program To Draw Lines in Given Co-Ordinates Using DDA Algorithm

This program uses the DDA (Digital Differential Analyzer) algorithm to draw lines between points specified by (x1, y1) and (x2, y2) coordinates. It initializes the graphics mode, gets the coordinate inputs, calculates the slope and step increments between points, and uses a while loop to incrementally draw pixels between the points using the putpixel() function.

Uploaded by

Sunny Mishra
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

/* Program to draw lines in given co-ordinates using DDA

algorithm */

Source Code
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
clrscr();
float x,y,x1,y1,x2,y2,dx,dy,length,a,b;
int i,gd=DETECT,gm;
printf("enter the value of x1:\t");
scanf("%f",&x1);
printf("enter the value of y1:\t");
scanf("%f",&y1);
printf("enter the value of x2:\t");
scanf("%f",&x2);
printf("enter the value of y2:\t");
scanf("%f",&y2);
initgraph(&gd,&gm,"c:\\tc\\bgi");
a=getmaxx();
b=getmaxy();
line(a/2,0,a/2,b);
line(0,b/2,a,b/2);
dx=abs(x2-x1);
dy=abs(y2-y1);
if(dx>=dy)
length=dx;
else
length=dy;
dx=(x2-x1)/length;
dy=(y2-y1)/length;
x=x1+.5;/*factor .5 is added to round the values*/
y=y1+.5;/*factor .5 is added to round the values*/
i=1;
while(i<=length)
{
putpixel((a/2)+x,(b/2)-y,15);
x=x+dx;
y=y+dy;
i=i+1;
}
getch();
}

Output:
IIMT ENGINEERING COLLEGE
MEERUT

Computer Graphics
Lab File

SUBMITTED TO :- SUBMITTED BY:-

Ms.Nancy Rastogi Rohit Maurya

Roll No- 0812713073

IT-B 5th Sem


Page Faculty
S.No Date Practical Name No Signature

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.

Index

You might also like