DDA Line Drawing Program in C


File size: 912 Bytes

File content type: text/plain

Category: Practical Files

Subject: Computer Graphics and Multimedia

#include<stdio.h> #include<dos.h> #include<graphics.h> #include<math.h> #include<conio.h> void lineDDA(int x1, int y1, int x2, int y2) { int dx,dy,steps,k,x,y,xincrement, yincrement; dx = x2-x1; dy = y2-y1; if(abs(dx)>abs(dy)) steps = abs(dx); else steps = abs(dy); xincrement = dx/steps; yincrement = dy/steps; x = x1; y = y1; putpixel(x,y,67); for(k=0;k<steps;k++) { x += xincrement; y += yincrement; putpixel(x,y,67); delay(20); } } void main() { int x1,y1,x2,y2; int gd = DETECT, gm = DETECT; initgraph(&gd, &gm, ""); printf("Enter the starting coordinates of line:\n"); scanf("%d %d", &x1, &y1); printf("Enter the ending coordinates of line:\n"); scanf("%d %d", &x2, &y2); lineDDA(x1, y1, x2, y2); getch(); }

Related searches DDA line drawing algorithm in C, C Program to Draw a Line Using DDA Algorithm

Last Updated: July 16, 2022