50% found this document useful (6 votes)
17K views2 pages

Rectangle Using DDA Line Drawing Algo

This program uses the Digital Differential Analyzer (DDA) line drawing algorithm to draw a rectangle on a graph by calling the ddaline function four times to connect the points (10,10) to (10,50) to (50,50) to (50,10) to (10,10). The ddaline function takes the x and y coordinates of the start and end points, along with a color value, and uses incremental steps of the change in x and y to plot each pixel along the line.

Uploaded by

sukhman92
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
50% found this document useful (6 votes)
17K views2 pages

Rectangle Using DDA Line Drawing Algo

This program uses the Digital Differential Analyzer (DDA) line drawing algorithm to draw a rectangle on a graph by calling the ddaline function four times to connect the points (10,10) to (10,50) to (50,50) to (50,10) to (10,10). The ddaline function takes the x and y coordinates of the start and end points, along with a color value, and uses incremental steps of the change in x and y to plot each pixel along the line.

Uploaded by

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

Program 19: Program to draw a rectangle using DDA line drawing algorithm. #include<graphics.h> #include<conio.h> #include<math.

h> #define ROUND(x) ((int)(x+0.5)) void ddaline(int x1, int y1, int x2, int y2, int c) { int dx = x2 - x1; int dy = y2 - y1; int steps; if(abs(dx) > abs(dy)) steps = abs(dx); else steps = abs(dy); float x_inc = dx / (float)steps; float y_inc = dy / (float)steps; int x = x1, y = y1; putpixel(x, y, c); for (int i = 0; i < steps; ++i) { x += x_inc; y += y_inc; putpixel(ROUND(x), ROUND(y), c); } } void main() { int gd = DETECT, gm; initgraph(&gd, &gm, "O:\\bgi"); ddaline(10, ddaline(10, ddaline(50, ddaline(10, getch(); } 10, 10, 10, 50, 50, 10, 50, 50, 10, 50, 50, 50, 111); 111); 111); 111);

You might also like