Skip to content

Instantly share code, notes, and snippets.

@Ziggoto
Created December 13, 2016 16:29
Show Gist options
  • Save Ziggoto/b26039c665823f14615ec31eb8759c44 to your computer and use it in GitHub Desktop.
Save Ziggoto/b26039c665823f14615ec31eb8759c44 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
matrix = [[None for j in xrange(10)] for i in xrange(10)]
def print_matrix():
for line in matrix:
for col in line:
print str(col)+'\t',
print ''
def plot(x, y, D):
print 'pinta ({}, {}). D = {}'.format(x, y, D)
matrix[x][y] = 'X'
def bresenham(x0, y0, x1, y1):
dx = x1 - x0
dy = y1 - y0
D = dy - dx
y = y0
for x in range(x0, x1):
plot(x,y,D)
if D >= 0:
'''
Se a reta cresce mais em Y que em X, ele retira a variação em X?
'''
y += 1
D -= dx
D += dy
if __name__ == '__main__':
bresenham(0, 1, 6, 4)
print ''
print print_matrix()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment