Advertisement
EtzGamer

[CC API] Circles 2

Jul 3rd, 2016
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.50 KB | None | 0 0
  1. --[[
  2. .   Circles 2 Release
  3. .   by EtzGamer (2016)
  4. .  
  5. .   To use this API in any other programs, APIs, OSes,
  6. .   you are required to give visually visible credits
  7. .   in your program/ OS that is accessible by the users
  8. .   or within the first 20 lines of your API code,
  9. .   clearly visible by those viewing the code.
  10. .  
  11. .   Variable Ref:
  12. .   aC = Alpha Calibrated
  13. .   c = Color
  14. .   cN = Color toNumber(ed)
  15. .   x = Center X
  16. .   y = Center Y
  17. .   dX = Delta X
  18. .   dXF = Delta X Floor(ed)
  19. .   dY = Delta Y
  20. .   dYF = Delta X Floor(ed)
  21. .   oC = Outline Color
  22. .   oCN = Outline Color toNumber(ed)
  23. --]]
  24.  
  25. local version = "2.0.3r"
  26.  
  27. if not (term.isColor) then
  28.     error("Circles requires advanced computer.")
  29. end
  30.  
  31. function version()
  32.     return version
  33. end
  34.  
  35. function drawCircle(r, x, y, c)
  36.     if (r == nil) or (x == nil) or (y == nil) then
  37.         error("Some params are empty")
  38.     end
  39.     local dX, dY, dYC = 0, 0, 0
  40.     local cN = tonumber(c)
  41.     while dY <= dX do
  42.         dX = math.sqrt(r * r - dY * dY)
  43.         dYC = dY / 1.5
  44.         paintutils.drawPixel(x + dX, y - dYC, cN)
  45.         paintutils.drawPixel(x + dX, y + dYC, cN)
  46.         paintutils.drawPixel(x - dX, y - dYC, cN)
  47.         paintutils.drawPixel(x - dX, y + dYC, cN)
  48.         dY = dY + 1
  49.     end
  50.     dX, dY = 0, 0
  51.     while dX <= dY do
  52.         dY = math.sqrt(r * r - dX * dX)
  53.         dYC = dY / 1.5
  54.         paintutils.drawPixel(x + dX, y - dYC, cN)
  55.         paintutils.drawPixel(x + dX, y + dYC, cN)
  56.         paintutils.drawPixel(x - dX, y - dYC, cN)
  57.         paintutils.drawPixel(x - dX, y + dYC, cN)
  58.         dX = dX + 1
  59.     end
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement