|
ToDo:
|
呑みすぎたー。
def bresenham(x1,y1,x2,y2):
dx = abs(x2 - x1)
dy = abs(y2 - y1)
e = 0
if ( dx > dy ):
y = y1
p = 1 if x2 > x1 else -1
for x in range(x1,x2,p):
e += dy
if ( e > dx ):
e -= dx
y += (1 if y2 > y1 else -1)
print "%d,%d" % (x,y)
else:
x = x1
p = 1 if y2 > y1 else -1
for y in range(y1,y2,p):
e += dx
if (e > dy):
e -= dy
x += (1 if x2 > x1 else -1)
print "%d,%d" % (x,y)
print "%d,%d" % (x2,y2)
if __name__ == '__main__':
bresenham(2,1,16,10)