Skip to content

Instantly share code, notes, and snippets.

@luthfianto
Created September 29, 2014 12:48
Show Gist options
  • Save luthfianto/8eb8c76c85f00477329c to your computer and use it in GitHub Desktop.
Save luthfianto/8eb8c76c85f00477329c to your computer and use it in GitHub Desktop.
Digital Differential Analyzer in JavaScript
function dda(x0, y0, x1, y1)
{
const dx = x1 - x0,
dy = y1 - y0,
s = Math.abs(dx) > Math.abs(dy) ? Math.abs(dx) : Math.abs(dy),
xi = dx * 1.0 / s,
yi = dy * 1.0 / s
var x = x0,
y = y0,
out= []
out.push({x: x0, y: y0});
for (var i = 0; i < s; i++) {
x += xi;
y += yi;
out.push({x: x, y: y});
}
return out
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment