Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local lib = {backgroundColor = colors.black, redir = term.native()}
- local logLine = 1
- function lib.puWrap(f, ...)
- term.current(lib.redir)
- f(...)
- term.setBackgroundColor(lib.backgroundColor)
- end
- function lib.print(...)
- term.redirect(term.native())
- local _, maxLine = term.getSize()
- if logLine < maxLine then
- term.setCursorPos(1, logLine)
- print(...)
- logLine = logLine + 1
- else
- term.scroll(1)
- term.setCursorPos(1, logLine)
- print(...)
- end
- term.redirect(lib.redir)
- end
- local function createElement(x, y)
- x = x or 1
- y = y or 1
- local self = {x = x, y = y}
- local draw = function() lib.print("drawed at " .. self.x .. ", " .. self.y) end
- local getPosition = function() return self.x, self.y end
- local setPosition = function(xNew, yNew) self.x = xNew; self.y = yNew end
- return {
- draw = draw,
- getPosition = getPosition,
- setPosition = setPosition
- }
- end
- function lib.newPixel(x, y, color)
- x = x or 1
- y = y or 1
- color = color or colors.white
- local self = {color = color, xprev = nil, yprev = nil}
- local o = {}
- setmetatable(o, {__index = createElement(x, y)})
- local super = getmetatable(o).__index
- o.setColor = function(newColor) self.color = newColor end
- o.getColor = function() return self.color end
- o.draw = function()
- if self.xprev then lib.puWrap(paintutils.drawPixel, self.xprev, self.yprev, lib.backgroundColor) end
- super.draw()
- local xcur, ycur = o.getPosition()
- lib.puWrap(paintutils.drawPixel, xcur, ycur, self.color)
- end
- o.setPosition = function(xNew, yNew)
- self.xprev, self.yprev = o.getPosition()
- super.setPosition(xNew, yNew)
- end
- return o
- end
- function lib.init()
- term.redirect(term.native())
- term.setBackgroundColor(lib.backgroundColor)
- term.clear()
- term.redirect(lib.redir)
- term.setBackgroundColor(lib.backgroundColor)
- term.clear()
- end
- return lib
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement