Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _G.pix = {}
- _G.litpix = {}
- _G.epix = {}
- litpix.pushed = true
- litpix.bgc = colors.black
- local function isOdd(x)
- return (x % 2) > 0
- end
- local function exists(y, x)
- if pix[y] ~= nil then
- if pix[y][x] ~= nil then
- return true
- end
- end
- return false
- end
- local function render()
- term.current().setVisible(false)
- term.clear()
- y = 0
- k = 0
- for z = 1, 20 do
- if isOdd(y) then k = k + 1 end
- for x = 1, 51 do
- if isOdd(y) then
- term.setTextColor(litpix.bgc); term.setBackgroundColor(litpix.bgc)
- if exists(k, x) then term.setTextColor(pix[k][x]) end
- if exists(k+1, x) then term.setBackgroundColor(pix[k+1][x]) end
- term.setCursorPos(x, z)
- term.write("\143")
- term.setTextColor(litpix.bgc); term.setBackgroundColor(litpix.bgc)
- else
- term.setTextColor(litpix.bgc); term.setBackgroundColor(litpix.bgc)
- if exists(k, x) then term.setTextColor(pix[k][x]) end
- if exists(k+1, x) then term.setBackgroundColor(pix[k+1][x]) end
- term.setCursorPos(x, z)
- term.write("\131")
- term.setTextColor(litpix.bgc); term.setBackgroundColor(litpix.bgc)
- end
- end
- y = y + 1
- k = k + 1
- end
- term.current().setVisible(true)
- end
- litpix.setBackgroundColor = function(c)
- litpix.bgc = c
- end
- litpix.createSymbol = function(s) return s end
- litpix.createPallete = function(s) return s end
- litpix.drawSymbol = function(sx, sy, s, p)
- for y = 1, #s do
- for x = 1, #s[y] do
- if s[y][x] ~= 0 then
- if pix[y+sy-1] == nil then pix[y+sy-1] = {} end
- pix[y+sy-1][x+sx-1] = p[s[y][x]]
- end
- end
- end
- end
- litpix.push = function()
- litpix.pushed = false
- end
- litpix.pop = function()
- litpix.pushed = true
- render()
- end
- litpix.clear = function()
- for i, v in pairs(pix) do
- pix[i] = {}
- end
- if litpix.pushed then render() end
- end
- litpix.addPixel = function(x, y, c)
- if pix[y] == nil then pix[y] = {} end
- pix[y][x] = c
- end
- litpix.drawPixel = function(x, y, c)
- litpix.addPixel(x, y, c)
- if litpix.pushed then render() end
- end
- litpix.addLine = function(x1, y1, x2, y2, c)
- delta_x = x2 - x1
- ix = delta_x > 0 and 1 or -1
- delta_x = 2 * math.abs(delta_x)
- delta_y = y2 - y1
- iy = delta_y > 0 and 1 or -1
- delta_y = 2 * math.abs(delta_y)
- litpix.addPixel(x1, y1, c)
- if delta_x >= delta_y then
- error = delta_y - delta_x / 2
- while x1 ~= x2 do
- if (error >= 0) and ((error ~= 0) or (ix > 0)) then
- error = error - delta_x
- y1 = y1 + iy
- end
- error = error + delta_y
- x1 = x1 + ix
- litpix.addPixel(x1, y1, c)
- end
- else
- error = delta_x - delta_y / 2
- while y1 ~= y2 do
- if (error >= 0) and ((error ~= 0) or (iy > 0)) then
- error = error - delta_y
- x1 = x1 + ix
- end
- error = error + delta_x
- y1 = y1 + iy
- litpix.addPixel(x1, y1, c)
- end
- end
- if litpix.pushed then render() end
- end
- litpix.drawRect = function(x1, y1, x2, y2, co, recurse)
- recurse = recurse or false
- if recurse then
- for x = x1, x2 do
- for y = y1, y2 do
- litpix.addPixel(x, y, co)
- end
- end
- else
- for x = x1, x2 do
- litpix.addPixel(x, y1, co)
- litpix.addPixel(x, y2, co)
- end
- for y = y1, y2 do
- litpix.addPixel(x1, y, co)
- litpix.addPixel(x2, y, co)
- end
- end
- end
- litpix.drawLine = function(x1, y1, x2, y2, c)
- litpix.addLine(x1, y1, x2, y2, c)
- if litpix.pushed then render() end
- end
- litpix.drawPoly = function(...)
- local a = {...}
- local k = (#a-1)/2
- local j = 1
- for i = 1, k do
- if i < k then litpix.addLine(a[j], a[j+1], a[j+2], a[j+3], a[(k*2)+1])
- else litpix.addLine(a[j], a[j+1], a[1], a[2], a[(k*2)+1]) end
- j = j + 2
- end
- if litpix.pushed then render() end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement