From bcfbb4af65592f201c46e288494256e5546f0e30 Mon Sep 17 00:00:00 2001 From: KomalpKaur <51746326+KomalpKaur@users.noreply.github.com> Date: Tue, 15 Oct 2019 00:07:50 +0530 Subject: [PATCH] Update lineusingdda.cpp --- lineusingdda.cpp | 69 ++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/lineusingdda.cpp b/lineusingdda.cpp index 2aef58a..207afa7 100644 --- a/lineusingdda.cpp +++ b/lineusingdda.cpp @@ -1,38 +1,43 @@ -#include +#include +#include #include -#include -using namespace std; - -void DDA(int X0,int Y0, int X1, int Y1) +#include +void main() { - int dx = X1-X0; - int dy = Y1-Y0; - //To count no of steps. - 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; - //Loop to display all the points between the end points. - for (int i = 0; i <= steps; i++) - { - putpixel (X,Y,100); - X += Xinc; - Y += Yinc; - delay(5); - + +int gd=DETECT,gm; +int x1,x2,y1,y2,i; +float x,y,steps,dx,dy; +initgraph(&gd,&gm,"C:\\TURBOC3\\BGI"); + +cout<<"Enter first point (x1,y1)"; +cin>>x1>>y1; +cout<<"Enter second point (x2,y2)"; +cin>>x2>>y2; +dx=(float)(x2-x1); +dy=(float)(y2-y1); + +if(dx>=dy) +{steps=dx; +} +else +{steps=dy; } -} -int main() + +dx=dx/steps; +dy=dy/steps; +x=x1; +y=y1; +for(i=1;i<=steps;i++) { -int X0,Y0,X1,Y1; -//Input the co ordinates from the user. -cout<<"Enter the four coordinates: "<>X0>>Y0>>X1>>Y1; -int gd = DETECT, gm; -initgraph(&gd,&gm, NULL); -DDA(X0,Y0,X1,Y1); -delay(50000); + putpixel(x,y,RED); + x+=dx; + y+=dy; +} +getch(); closegraph(); -return 0; + } + + +