Skip to content

Commit

Permalink
Added DDA
Browse files Browse the repository at this point in the history
  • Loading branch information
suriya-1403 authored Mar 2, 2021
1 parent 396971d commit 62950b2
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions DDA.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>

int abs (int n)
{
return ( (n>0) ? n : ( n * (-1)));
}

void DDA(int X0, int Y0, int X1, int Y1)
{
int i;
int dx = X1 - X0;
int dy = Y1 - Y0;

int steps = abs(dx) > abs(dy) ? abs(dx) : abs(dy);

float Xinc = dx / (float) steps;
float Yinc = dy / (float) steps;

float X = X0;
float Y = Y0;
for (i = 0; i <= steps; i++)
{
int tempx=round(X);
int tempy=round(Y);
putpixel (tempx,tempy,BLUE);
X += Xinc;
Y += Yinc;
delay(100);

}
}

int main()
{
int gd = DETECT, gm;
initgraph (&gd, &gm, "C:\\Turboc3\\BGI");
// int X1=2, Y1=1, X2=12, Y2=6;
DDA(2,1,12,6);
return 0;
}

0 comments on commit 62950b2

Please sign in to comment.