NeoKat

NeoX

Aug 22nd, 2015
70
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require("component")
  2. local event = require("event")
  3. local thread = require("thread")
  4.  
  5. local gpu = component.gpu
  6. local computer = component.computer
  7.  
  8. local Neo2D, NeoInput, NeoAudio = {}, {}, {}
  9. local Neo2D_, NeoInput_, NeoAudio_ = {}, {}, {}
  10.  
  11. thread.init()
  12.  
  13. ------------------------------------------------------------------
  14.  
  15. function Neo2D_.Text(x, y, text, tC, rend)
  16.   if type(rend) ~= "table" then
  17.     rend = gpu
  18.   end
  19.   for xx = 1, #text do
  20.     local tmp, tmp1, bC, tmp2, tmp3 = rend.get(x + xx - 1, y)
  21.     local tmpBC = rend.setBackground(bC)
  22.     local tmpTC = rend.setForeground(tC)
  23.     rend.set(x + xx - 1, y, string.sub(text, xx, xx))
  24.     rend.setBackground(tmpBC)
  25.     rend.setForeground(tmpTC)
  26.   end
  27. end
  28.  
  29. function Neo2D_.Box(x, y, width, height, bC, rend)
  30.   if type(rend) ~= "table" then
  31.     rend = gpu
  32.   end
  33.   tmpBC = rend.setBackground(bC)
  34.   rend.fill(x, y, width, height, " ")
  35.   rend.setBackground(tmpBC)
  36. end
  37.  
  38. function Neo2D_.Point(x, y, bC, rend)
  39.   if type(rend) ~= "table" then
  40.     rend = gpu
  41.   end
  42.   tmpBC = rend.setBackground(bC)
  43.   rend.set(x, y, " ")
  44.   rend.setBackground(tmpBC)
  45. end
  46.  
  47. function Neo2D_.Circle(xc, yc, width, height, bC, rend)
  48.   if type(rend) ~= "table" then
  49.     rend = gpu
  50.   end
  51.   tmpBC = rend.setBackground(bC)
  52.  
  53.   local a2 = width * width
  54.   local b2 = height * height
  55.   local fa2, fb2 = 4 * a2, 4 * b2
  56.   local x, y, sigma = 0, height, 2*b2+a2*(1-2*height)
  57.  
  58.   while true do
  59.     if not ((b2*x) <= (a2*y)) then
  60.       break
  61.     end
  62.     rend.set(xc + x, yc + y, " ")
  63.     rend.set(xc - x, yc + y, " ")
  64.     rend.set(xc + x, yc - y, " ")
  65.     rend.set(xc - x, yc - y, " ")
  66.     if sigma >= 0 then
  67.       sigma = sigma + (fa2 * (1 - y))
  68.       y = y - 1
  69.     end
  70.     sigma = sigma + (b2 * ((4 * x) + 6))
  71.     x = x + 1
  72.   end
  73.  
  74.   x, y, sigma = width, 0, 2*a2+b2*(1-2*width)
  75.  
  76.   while true do
  77.     if not ((a2*y) <= (b2*x)) then
  78.       break
  79.     end
  80.     y = y + 1
  81.     rend.set(xc + x, yc + y, " ")
  82.     rend.set(xc - x, yc + y, " ")
  83.     rend.set(xc + x, yc - y, " ")
  84.     rend.set(xc - x, yc - y, " ")
  85.     if sigma >= 0 then
  86.       sigma = sigma + (fb2 * (1 - x))
  87.       x = x - 1
  88.     end
  89.     sigma = sigma + (a2 * ((4 * y) + 6))
  90.     y = y + 1
  91.   end
  92.   rend.setBackground(tmpBC)
  93. end
  94.  
  95. function NeoAudio_.Beep()
  96.   computer.beep()
  97. end
  98.  
  99. ------------------------------------------------------------------
  100.  
  101. function Neo2D.Text(...)
  102.   thread.create(Neo2D_.Text, ...)
  103. end
  104.  
  105. function Neo2D.Box(...)
  106.   thread.create(Neo2D_.Box, ...)
  107. end
  108.  
  109. function Neo2D.Point(...)
  110.   thread.create(Neo2D_.Point, ...)
  111. end
  112.  
  113. function Neo2D.Circle(...)
  114.   thread.create(Neo2D_.Circle, ...)
  115. end
  116.  
  117. local NeoX = {Neo2D = Neo2D, NeoAudio = NeoAudio, NeoInput = NeoInput}
  118.  
  119. ------------------------------------------------------------------
  120.  
  121. return NeoX
RAW Paste Data