Digital differential analyzer (graphics algorithm): Difference between revisions

Content deleted Content added
changed the program section from featuring the code in a list to a code block
Fixed the indentation of the sample code
Line 35:
 
== Program ==
DDA algorithm Program in C++:<syntaxhighlight lang="c++" line="1">
#include<graphics.h>
 
<syntaxhighlight lang="c++" line="1">
#include<iostream.h>
#include <mathgraphics.h>
 
#include<dos.h>
#include <conioiostream.h>
#include <graphicsmath.h>
#void main( )
#include <iostreamdos.h>
#include <dosconio.h>
 
#void 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;
cin >> x1 >> y1;
cout << "Enter the value of x2 and y2: ";
cin >> x2 >> y2;
dx=abs(x2-x1);
dy dx = abs(y2x2 -y1 x1);
dy = abs(y2 - y1);
if(dx >= dy)
step = dx;
else
step=dy;
dx=dx/ step = dy;
dy dx =dy dx / step;
dy = dy / step;
x=x1;
y x =y1 x1;
i y =1 y1;
i = 1;
while(i <= step) {
{
putpixel(x, y, 5);
x = x + dx;
y = y + dy;
i = i + 1;
delay(100);
}
getch();
closegraph();
}
</syntaxhighlight>
 
== See also ==