Skip to content

Instantly share code, notes, and snippets.

@z1nc0r3
Last active February 6, 2023 19:14
Show Gist options
  • Save z1nc0r3/9552a002160fb2a4ed9dbb680932c0e2 to your computer and use it in GitHub Desktop.
Save z1nc0r3/9552a002160fb2a4ed9dbb680932c0e2 to your computer and use it in GitHub Desktop.
DDA Line Algorithm
void ddaLine(float xa, float ya, float xb, float yb) {
int dx = xb - xa, dy = yb - ya;
int k, steps;
float xinc, yinc, x = xa, y = ya;
if (abs(dx) > abs(dy)) {
steps = abs(dx);
}
else {
steps = abs(dy);
}
xinc = (float) dx / steps;
yinc = (float) dy / steps;
putPixel(x, y);
for (k = 0; k < steps; k++) {
x += xinc;
y += yinc;
putPixel(x, y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment