DDA – Digital Differential Analyzer line algorithm C++ Code
Learn here DDA – Digital Differential Analyzer line algorithm C++ Code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
#include<bits/stdc++.h> #include<graphics.h> using namespace std; int main( ) { float x,y,x1,y1,x2,y2,dx,dy,step; int i,gd=DETECT,gm; initgraph(&gd,&gm,"c:\\turboc3\\bgi"); cout<<"Enter the value of x1 and y1 : "; cin>>x1>>y1; cout<<"Enter the value of x2 and y2: "; cin>>x2>>y2; dx=abs(x2-x1); dy=abs(y2-y1); if(dx>=dy) step=dx; else step=dy; dx=dx/step; dy=dy/step; x=x1; y=y1; i=1; while(i<=step) { putpixel(x,y,5); x=x+dx; y=y+dy; i=i+1; delay(100); } return 0; } |
Thanks for viewing DDA algorithm code.