0% found this document useful (0 votes)
12 views2 pages

DDA Algorithm Line Drawing Program

The document provides code to draw a line between two points (x1, y1) and (x2, y2) using the Digital Differential Analyzer (DDA) algorithm. The code calculates the change in x and y between the points, determines which value has a greater change to use as increments, plots each point along the line using putpixel(), and delays drawing to slow down the animation.

Uploaded by

Mayank
Copyright
© All Rights Reserved
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)
12 views2 pages

DDA Algorithm Line Drawing Program

The document provides code to draw a line between two points (x1, y1) and (x2, y2) using the Digital Differential Analyzer (DDA) algorithm. The code calculates the change in x and y between the points, determines which value has a greater change to use as increments, plots each point along the line using putpixel(), and delays drawing to slow down the animation.

Uploaded by

Mayank
Copyright
© All Rights Reserved
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

Write a program to draw a line of slope between 0 and 1 using DDA

algorithm
#include <graphics.h>

#include <stdio.h>

#include <conio.h>

#include <dos.h>

void main( )

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

int i,gd=DETECT,gm;

initgraph(&gd,&gm,"C:\\TC\\BGI");

printf("Enter the value of x1 and y1 : ");

scanf("%f%f",&x1,&y1);

printf("Enter the value of x2 and y2: ");

scanf("%f%f",&x2,&y2);

dx=abs(x2-x1);

dy=abs(y2-y1);

if(dx>=dy)

step=dx;

else

step=dy;

dx=dx/step;

dy=dy/step;

x=x1;

y=y1;

i=1;

while(i<=step)

putpixel(x,y,5);

x=x+dx;

y=y+dy;
i=i+1;

delay(50);

getch();

closegraph();

You might also like