computer-graphics/lecture04-task01-section-translation.js
// works only for x > y
works only for x > y
works only for x > y
function drawLineWithTranslation(x0, x1, y0, y1, m, n, fillColor) {
        ctx.fillStyle = fillColor;
        x0 = x0 + m;
        x1 = x1 + n;
        let deltaX = x1 - x0;
        let deltaY = y1 - y0;
        let error = 0;
        let deltaError = Math.abs(deltaY / deltaX)    
        y = y0
        for (let x = x0; x < x1; x++) {
            drawPixel(ctx, x, y,canvasScaleFactor);
            error = error + deltaError;
            if (error >= 0.5) {
                y = y + 1;
                error = error - 1;
            }
        }
    }
function drawLineWithTranslation ( x0 , x1 , y0 , y1 , m , n , fillColor ) { ctx . fillStyle = fillColor ; x0 = x0 + m ; x1 = x1 + n ; let deltaX = x1 - x0 ; let deltaY = y1 - y0 ; let error = 0 ; let deltaError = Math . abs ( deltaY / deltaX ) y = y0 for ( let x = x0 ; x < x1 ; x ++ ) { drawPixel ( ctx , x , y , canvasScaleFactor ) ; error = error + deltaError ; if ( error >= 0.5 ) { y = y + 1 ; error = error - 1 ; } } }
works only for x > y
works only for x > y