From 62950b2cf2d96e20745588fec895333284e19bfa Mon Sep 17 00:00:00 2001 From: SuriyaKrishnan Date: Tue, 2 Mar 2021 15:09:56 +0530 Subject: [PATCH] Added DDA --- DDA.C | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 DDA.C diff --git a/DDA.C b/DDA.C new file mode 100644 index 0000000..ed6a2f3 --- /dev/null +++ b/DDA.C @@ -0,0 +1,43 @@ +#include +#include +#include +#include + +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; +}