Hola,

Estoy trtando de escribir en P5 una funcion que implemente el
algoritmo de Bresenham para dibujar lineas, ya tengo una parte escrita
pero aun no hace su mision bien, tal vez alguien en la lista pueda
darme una pista de mi error?

zea

<code>

void bresenham(int x0, int y0, int x1, int y1){
    boolean step = abs(y1-y0) > abs(x1-x0);
    if (step){
        x0 = y0;
        x1 = y1;
    }

    if (x0 > x1){
        x0 = x1;
        y0 = y1;
    }

    int deltax = x1-x0;
    int deltay = abs(y1-y0);
    float error = 0;
    float deltaerr = deltay/deltax;

    int ystep;
    int y = y0;

    if (y0 < y1){
        ystep = 1;
    } else {
        ystep = -1;
    }

    for (int i = x0; i <= x1; i++){
        if (step) {
            //stroke (0,255,0);
            point (y,(random(-1,1)+i));
            //point (y,i);
        }else{
            point ((random(-1,1)+i),y);
            //point (i,y);
        }

        error = error + deltaerr;

        if (error >= 0.5){
            y = y + ystep;
            error = error - 1;
        }
    }
}

</code>

-- 
Gabriel Zea
===============================
http://twitter.com/z3a
http://zea.randomlab.net -> Portfolio
http://nerdbots.info -> Experimental lab
http://randomlab.net -> Art Host
_______________________________________________
____ ____ ___  ____ _  _ ___
|__| |__/   /  |___  \/  |__]
|  | |  \  /__ |___ _/\_ |

Arzexp mailing list
[email protected]
http://lists.slow.tk/listinfo.cgi/arzexp-slow.tk

Responder a