Like this (it's not accurate)
How can I change the Bresenham line algorithm to keep cycling into itself and create this effect: (Drawning not accurate)
I have the basic line with 2 coordinates:
drawBresenhamLine = function (x0, y0, x1, y1) {
var dx, dy, e2, err, sx, sy;
console.log('Called LBR : ' + x0 + ',' + y0 + '->' + x1 + ',' + y1);
dx = Math.abs(x1 - x0);
sx = x0 < x1 ? 1 : -1;
dy = Math.abs(y1 - y0);
sy = y0 < y1 ? 1 : -1;
err = (dx > dy ? dx : -dy) / 2;
while (true) {
//console.log('Push : '+x0 +' ,'+ y0);
setPixel(x0, y0);
setEnd(x1,y1);
if (x0 === x1 && y0 === y1) {
break;
}
e2 = err;
if (e2 > -dx) {
err -= dy;
x0 += sx;
}
if (e2 < dy) {
err += dx;
y0 += sy;
}
}
return null;
};
setPixel(x,y)
changes the current pixel and drawBresenhamLine
will use its coords next iteration.