Digital differential analyzer (graphics algorithm): Difference between revisions

Content deleted Content added
Markzou (talk | contribs)
Markzou (talk | contribs)
Line 6:
== Sample Code ==
{{Citation}}
 
void line DDA(int xa, int ya, int xb, int yb)
 
{
int dx=xb-xa, dy=yb-ya, steps, k;
 
float xIncrement, yIncrement, x=xa, y=ya;
int dx=xb-xa, dy=yb-ya, steps, k;
if(abs(dx)>abs(dy)) steps=abs(dx);
 
else steps=abs(dy);
float xIncrement, yIncrement, x=xa, y=ya;
xIncrement=dx/(float)steps;
 
yIncrement=dy/(float)steps;
if(abs(dx)>abs(dy)) steps=abs(dx);
setPixel(ROUND(x), ROUND(y));
 
for(k=0; k<steps; k++)
else steps=abs(dy);
{
 
x += xIncrement;
y += yIncrement;
 
setPixel(ROUND(x), ROUND(y));
xIncrement=dx/(float)steps;
}
 
yIncrement=dy/(float)steps;
 
 
setPixel(ROUND(x), ROUND(y));
 
for(k=0; k<steps; k++)
 
{
 
x += xIncrement;
 
y += yIncrement;
 
setPixel(ROUND(x), ROUND(y));
 
}
 
}