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

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)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
50% found this document useful (6 votes)
17K views

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)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy