Advertisement
Fra146

DrawFilledBox

Dec 15th, 2020
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. function drawFilledBox(startX, startY, endX, endY, nColour)
  2. if type(startX) ~= "number" or type(startX) ~= "number" or
  3. type(endX) ~= "number" or type(endY) ~= "number" or
  4. (nColour ~= nil and type(nColour) ~= "number") then
  5. error("Expected startX, startY, endX, endY, colour", 2)
  6. end
  7.  
  8. startX = math.floor(startX)
  9. startY = math.floor(startY)
  10. endX = math.floor(endX)
  11. endY = math.floor(endY)
  12.  
  13. if nColour then
  14. term.setBackgroundColor(nColour)
  15. end
  16. if startX == endX and startY == endY then
  17. drawPixelInternal(startX, startY)
  18. return
  19. end
  20.  
  21. local minX = math.min(startX, endX)
  22. if minX == startX then
  23. minY = startY
  24. maxX = endX
  25. maxY = endY
  26. else
  27. minY = endY
  28. maxX = startX
  29. maxY = startY
  30. end
  31.  
  32. for x = minX, maxX do
  33. for y = minY, maxY do
  34. drawPixelInternal(x, y)
  35. end
  36. end
  37. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement