Digital differential analyzer (graphics algorithm): Difference between revisions

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