Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local thread = require("thread")
- local gpu = component.gpu
- local computer = component.computer
- local Neo2D, NeoInput, NeoAudio = {}, {}, {}
- local Neo2D_, NeoInput_, NeoAudio_ = {}, {}, {}
- thread.init()
- ------------------------------------------------------------------
- function Neo2D_.Text(x, y, text, tC, rend)
- if type(rend) ~= "table" then
- rend = gpu
- end
- for xx = 1, #text do
- local tmp, tmp1, bC, tmp2, tmp3 = rend.get(x + xx - 1, y)
- local tmpBC = rend.setBackground(bC)
- local tmpTC = rend.setForeground(tC)
- rend.set(x + xx - 1, y, string.sub(text, xx, xx))
- rend.setBackground(tmpBC)
- rend.setForeground(tmpTC)
- end
- end
- function Neo2D_.Box(x, y, width, height, bC, rend)
- if type(rend) ~= "table" then
- rend = gpu
- end
- tmpBC = rend.setBackground(bC)
- rend.fill(x, y, width, height, " ")
- rend.setBackground(tmpBC)
- end
- function Neo2D_.Point(x, y, bC, rend)
- if type(rend) ~= "table" then
- rend = gpu
- end
- tmpBC = rend.setBackground(bC)
- rend.set(x, y, " ")
- rend.setBackground(tmpBC)
- end
- function Neo2D_.Circle(xc, yc, width, height, bC, rend)
- if type(rend) ~= "table" then
- rend = gpu
- end
- tmpBC = rend.setBackground(bC)
- local a2 = width * width
- local b2 = height * height
- local fa2, fb2 = 4 * a2, 4 * b2
- local x, y, sigma = 0, height, 2*b2+a2*(1-2*height)
- while true do
- if not ((b2*x) <= (a2*y)) then
- break
- end
- rend.set(xc + x, yc + y, " ")
- rend.set(xc - x, yc + y, " ")
- rend.set(xc + x, yc - y, " ")
- rend.set(xc - x, yc - y, " ")
- if sigma >= 0 then
- sigma = sigma + (fa2 * (1 - y))
- y = y - 1
- end
- sigma = sigma + (b2 * ((4 * x) + 6))
- x = x + 1
- end
- x, y, sigma = width, 0, 2*a2+b2*(1-2*width)
- while true do
- if not ((a2*y) <= (b2*x)) then
- break
- end
- y = y + 1
- rend.set(xc + x, yc + y, " ")
- rend.set(xc - x, yc + y, " ")
- rend.set(xc + x, yc - y, " ")
- rend.set(xc - x, yc - y, " ")
- if sigma >= 0 then
- sigma = sigma + (fb2 * (1 - x))
- x = x - 1
- end
- sigma = sigma + (a2 * ((4 * y) + 6))
- y = y + 1
- end
- rend.setBackground(tmpBC)
- end
- function NeoAudio_.Beep()
- computer.beep()
- end
- ------------------------------------------------------------------
- function Neo2D.Text(...)
- thread.create(Neo2D_.Text, ...)
- end
- function Neo2D.Box(...)
- thread.create(Neo2D_.Box, ...)
- end
- function Neo2D.Point(...)
- thread.create(Neo2D_.Point, ...)
- end
- function Neo2D.Circle(...)
- thread.create(Neo2D_.Circle, ...)
- end
- local NeoX = {Neo2D = Neo2D, NeoAudio = NeoAudio, NeoInput = NeoInput}
- ------------------------------------------------------------------
- return NeoX
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement