EtzGamer

[CC API] Circles 2 Beta

Jul 3rd, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.14 KB | None | 0 0
  1. --[[
  2. .   Circles 2 Beta
  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.3b"
  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.         --[[paintutils.drawPixel(x + dX + 1, y - dY, cN)
  59.         paintutils.drawPixel(x + dX + 1, y + dY, cN)
  60.         paintutils.drawPixel(x - dX - 1, y - dY, cN)
  61.         paintutils.drawPixel(x - dX - 1, y + dY, cN)--]]
  62.         dX = dX + 1
  63.     end
  64. end
  65.  
  66. function drawFilledCircle(r, x, y, c, oC)
  67.     if (r == nil) or (x == nil) or (y == nil) then
  68.         error("Some params are empty")
  69.     end
  70.     local cN = tonumber(c)
  71.     local cN = tonumber(c)
  72.     for i = 0, 90 do
  73.         dX = math.sin(i)*r
  74.         dY = math.cos(i)*r
  75.         dXF = math.floor(dX)
  76.         dYF = math.floor(dY)
  77.         paintutils.drawLine(x + dXF, y - dYF, x + dXF, y + dYF, cN)
  78.     end
  79.     if not (oC == "") then
  80.         local oCN = tonumber(oC)
  81.         drawCircle(r, x, y, oCN)
  82.     end
  83. end
Add Comment
Please, Sign In to add comment