”how to make the dda line using only the :* and # icons
. please answer please.
so I want to make my program on console.log view like this:
O……….
.O………
..O……..
…O…….
….O……
…..O…..
……O….
…….O…
……..O..
………O.
……….O
and this is like a diagonal but according to the name of my function dda where point a = 2.1 and point b = 8.5
you can immediately see the implementation of this in java form but only want it in javascript form
function dda(x1, y1, x2, y2) {
const
dx = x2 - x1,
dy = y2 - y1,
step = Math.abs(dx) > Math.abs(dy)
? Math.abs(dx)
: Math.abs(dy),
x_inc = dx / step,
y_inc = dy / step,
result = [];
for (let k = 0, x = x1, y = y1; k < step; k++) {
result.push([ Math.round(x), Math.round(y)]);
x += x_inc;
y += y_inc;
}
return result;
}
console.log(dda(2, 1, 8, 5));