/*
     Bresenham algorithm
     for line drawing.
     Requires a class to draw pixel, to build RDB color codes...
     Public domain source code, provided by scriptol.com
*/


void bresenham(int x0, int y0, int x1, int y1, Color color)  {
    int pix = color.getRGB();
    int dy = y1 - y0;
    int dx = x1 - x0;
    int stepx, stepy;

    if (dy &lt; 0)
        { dy = -dy;  stepy = -1; } 
    else 
        { stepy = 1; }
    if (dx &lt; 0)
       { dx = -dx;  stepx = -1; } 
     else
       { stepx = 1; }

    dy &lt;&lt;= 1;
    dx &lt;&lt;= 1;

    raster.setPixel(pix, x0, y0);
    if (dx &gt; dy)  {
        int fraction = dy - (dx >> 1);    
        while (x0 != x1) {
        if (fraction >= 0) {
            y0 += stepy;
            fraction -= dx;      
        }
        x0 += stepx;
        fraction += dy;     
        raster.setPixel(pix, x0, y0);
        }
    } 
    else  {
        int fraction = dx - (dy >> 1);
        while (y0 != y1) {
        if (fraction >= 0)  {
            x0 += stepx;
            fraction -= dy;
        }
        y0 += stepy;
        fraction += dx;
        raster.setPixel(pix, x0, y0);
        }
    }
}
