Advertisement
Knuffeliger

Pseudo Code: Bresenham Line Algorithm

Nov 10th, 2024
40
0
26 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. plotLine(x0, y0, x1, y1)
  2. dx = abs(x1 - x0)
  3. sx = x0 < x1 ? 1 : -1
  4. dy = -abs(y1 - y0)
  5. sy = y0 < y1 ? 1 : -1
  6. error = dx + dy
  7.  
  8. while true
  9. plot(x0, y0)
  10. if x0 == x1 && y0 == y1 break
  11. e2 = 2 * error
  12. if e2 >= dy
  13. error = error + dy
  14. x0 = x0 + sx
  15. end if
  16. if e2 <= dx
  17. error = error + dx
  18. y0 = y0 + sy
  19. end if
  20. end while
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement