Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Brasenham:
- def draw_line(self, x0, y0, x1, y1, screen):
- x0 = x0 // 32
- y0 = y0 // 32
- x1 = x1 // 32
- y1 = y1 // 32
- dx = abs(x1 - x0)
- dy = abs(y1 - y0)
- sx = 1 if x0 < x1 else -1
- sy = 1 if y0 < y1 else -1
- err = dx - dy
- x = x0
- y = y0
- while True:
- pixel_x = x * 32
- pixel_y = y * 32
- cube_rect = pygame.FRect(pixel_x, pixel_y, 32, 32)
- pygame.draw.rect(screen, 'white', cube_rect)
- if x == x1 and y == y1:
- break
- err2 = 2 * err
- if err2 > -dy:
- err -= dy
- x += sx
- if err2 < dx:
- err += dx
- y += sy
Advertisement
Add Comment
Please, Sign In to add comment