0% found this document useful (0 votes)
50 views

DDA Line Drawing Algorithm: #Include #Include #Include #Include

This document contains code for implementing the DDA (Digital Differential Analyzer) line drawing algorithm in C++. The code takes in x and y coordinates for starting and ending points, calculates the change in x and y, and uses incremental steps along those changes to plot each pixel along the line between the points. It initializes graphics mode, clears the screen, gets the input points, performs the DDA calculations, plots each pixel, and waits for user input before closing.

Uploaded by

Abhijit Temkar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

DDA Line Drawing Algorithm: #Include #Include #Include #Include

This document contains code for implementing the DDA (Digital Differential Analyzer) line drawing algorithm in C++. The code takes in x and y coordinates for starting and ending points, calculates the change in x and y, and uses incremental steps along those changes to plot each pixel along the line between the points. It initializes graphics mode, clears the screen, gets the input points, performs the DDA calculations, plots each pixel, and waits for user input before closing.

Uploaded by

Abhijit Temkar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

www.cglabprograms.

com

Dipin Krishna

DDA Line Drawing Algorithm

#include #include #include #include

<graphics.h> <stdio.h> <conio.h> <math.h>

void main() { int gd = DETECT, gm = DETECT, s, dx, dy, m, x1, y1, x2, y2; float xi, yi, x, y; clrscr(); printf("Enter the sarting point x1 & y1\n"); scanf("%d%d", &x1, &y1); printf("Enter the end point x2 & y2\n"); scanf("%d%d", &x2, &y2); initgraph(&gd, &gm, ""); cleardevice(); dx = x2 - x1; dy = y2 - y1; if (abs(dx) > abs(dy)) s = abs(dx); else s = abs(dy); xi = dx / (float) s; yi = dy / (float) s; x = x1; y = y1; putpixel(x1, y1, 4); for (m = 0; m < s; m++) { x += xi; y += yi; putpixel(x, y, 4); } getch(); }

www.cglabprograms.com

Dipin Krishna

You might also like