def bresenham_line(setter, x0, y0, x1, y1, color=None, colorFunc=None):
steep = abs(y1 - y0) > abs(x1 - x0)<EOL>if steep:<EOL><INDENT>x0, y0 = y0, x0<EOL>x1, y1 = y1, x1<EOL><DEDENT>if x0 > x1:<EOL><INDENT>x0, x1 = x1, x0<EOL>y0, y1 = y1, y0<EOL><DEDENT>dx = x1 - x0<EOL>dy = abs(y1 - y0)<EOL>err = dx / <NUM_LIT:2><EOL>if y0 < y1:<EOL><INDENT>ystep = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>ystep = -<NUM_LIT:1><EOL><DEDENT>count = <NUM_LIT:0><EOL>for x in range(x0, x1 + <NUM_LIT:1>):<EOL><INDENT>if colorFunc:<EOL><INDENT>color = colorFunc(count)<EOL>count += <NUM_LIT:1><EOL><DEDENT>if steep:<EOL><INDENT>setter(y0, x, color)<EOL><DEDENT>else:<EOL><INDENT>setter(x, y0, color)<EOL><DEDENT>err -= dy<EOL>if err < <NUM_LIT:0>:<EOL><INDENT>y0 += ystep<EOL>err += dx<EOL><DEDENT><DEDENT>
Draw line from point x0,y0 to x,1,y1. Will draw beyond matrix bounds.