Guest User

Untitled

a guest
Sep 23rd, 2025
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. class Brasenham:
  2. def draw_line(self, x0, y0, x1, y1, screen):
  3. x0 = x0 // 32
  4. y0 = y0 // 32
  5. x1 = x1 // 32
  6. y1 = y1 // 32
  7.  
  8.  
  9. dx = abs(x1 - x0)
  10. dy = abs(y1 - y0)
  11.  
  12. sx = 1 if x0 < x1 else -1
  13. sy = 1 if y0 < y1 else -1
  14.  
  15. err = dx - dy
  16.  
  17. x = x0
  18. y = y0
  19.  
  20. while True:
  21. pixel_x = x * 32
  22. pixel_y = y * 32
  23.  
  24. cube_rect = pygame.FRect(pixel_x, pixel_y, 32, 32)
  25. pygame.draw.rect(screen, 'white', cube_rect)
  26.  
  27. if x == x1 and y == y1:
  28. break
  29.  
  30. err2 = 2 * err
  31.  
  32. if err2 > -dy:
  33. err -= dy
  34. x += sx
  35.  
  36. if err2 < dx:
  37. err += dx
  38. y += sy
Advertisement
Add Comment
Please, Sign In to add comment