Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --v2.1
- local function update()
- shell.run("delete","lg")
- shell.run("pastebin","get","sSF7NPYC","lg")
- os.reboot()
- end
- local args = {...}
- if (args[1] == "update") then
- update()
- end
- function setup(name)
- sx,sy = nil
- buttons = {}
- pixels = {}
- local bg = colors.black
- sprites = {}
- inputs = {}
- if (name == "term") then
- sx,sy = term.getSize()
- else
- m = peripheral.wrap(name)
- term.redirect(m)
- sx,sy = m.getSize()
- end
- end
- function exit()
- term.native()
- end
- function drawText(x,y,color,colorb,text)
- term.setCursorPos(x,y)
- term.setTextColor(color)
- term.setBackgroundColor(colorb)
- term.write(text)
- end
- function clearScreen()
- term.clear()
- end
- function setBackgroundColor(color)
- term.setBackgroundColor(color)
- end
- function setTextColor(color)
- term.setTextColor(color)
- end
- function drawBT(name,x,xe,y,ye,color,colorb,text)
- term.setBackgroundColor(colorb)
- term.setTextColor(color)
- for i=x,xe do
- for g=y,ye do
- term.setCursorPos(i,g)
- term.write(" ")
- end
- end
- textline = (y + ye) / 2
- textline = string.format("%.1f", textline)
- textline = tonumber(textline)
- lines = {}
- for word in string.gmatch(text,"[^\n]+") do
- table.insert(lines,word)
- end
- if (#lines > 1) then
- for w=1,#lines do
- term.setCursorPos(x,y+w)
- term.write(lines[w])
- end
- else
- term.setCursorPos(x,textline)
- term.write(text)
- end
- table.insert(buttons,name..";"..x..";"..xe..";"..y..";"..ye)
- end
- function isButton(x,y)
- for i=1,#buttons do
- local parts = {}
- for word in string.gmatch(buttons[i],"[^;]+") do
- table.insert(parts,word)
- end
- name,bx,bxe,by,bye = parts[1],tonumber(parts[2]),tonumber(parts[3]),tonumber(parts[4]),tonumber(parts[5])
- if (bx-1 < x and x < bxe + 1 ) then
- if (by-1 < y and bye+1 > y) then
- return name
- end
- end
- end
- return false
- end
- function fill(x,x2,y,y2,color)
- term.setBackgroundColor(color)
- for i=x,x2 do
- for g=y,y2 do
- term.setCursorPos(i,g)
- pixels[x..y] = color
- term.write(" ")
- end
- end
- end
- function fillScreen(color)
- term.setBackgroundColor(color)
- term.clear()
- pixels = {}
- end
- function drawImage(x,y,name)
- image = paintutils.loadImage(name)
- paintutils.drawImage(image,x,y)
- end
- function getSize()
- local sizet = {}
- sizet.x = sx
- sizet.y = sy
- return sizet
- end
- function drawInput(name,x,x2,y,y2,limit)
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- for i=x,x2 do
- for g=y,y2 do
- term.setCursorPos(i,g)
- term.write(" ")
- end
- end
- table.insert(inputs,name..";"..x..";"..x2..";"..y..";"..y2..";"..limit)
- end
- function isInput(x,y)
- for i=1,#inputs do
- local parts = {}
- for word in string.gmatch(inputs[i],"[^;]+") do
- table.insert(parts,word)
- end
- name,bx,bxe,by,bye = parts[1],tonumber(parts[2]),tonumber(parts[3]),tonumber(parts[4]),tonumber(parts[5])
- if (bx-1 < x and x < bxe + 1 ) then
- if (by-1 < y and bye+1 > y) then
- return name
- end
- end
- end
- return false
- end
- function getInput(x,y)
- for i=1,#inputs do
- local parts = {}
- for word in string.gmatch(inputs[i],"[^;]+") do
- table.insert(parts,word)
- end
- name,bx,bxe,by,bye,limit = parts[1],tonumber(parts[2]),tonumber(parts[3]),tonumber(parts[4]),tonumber(parts[5]),tonumber(parts[6])
- if (bx-1 < x and x < bxe + 1 ) then
- if (by-1 < y and bye+1 > y) then
- term.setCursorPos(bx,by)
- local text = limitRead(limit)
- return text
- end
- end
- end
- return false
- end
- function lggSetDefBG(color)
- bg = color
- end
- function drawSprite(name,x,y,iname)
- image = paintutils.loadImage(iname)
- paintutils.drawImage(image,x,y)
- table.insert(sprites,name..";"..x..";"..y..";"..iname)
- end
- function moveSprite(name,x,y)
- for h=1,#sprites do
- local parts = {}
- term.setBackgroundColor(colors.black)
- for word in string.gmatch(sprites[h],"[^;]+") do
- table.insert(parts,word)
- end
- if (parts[1] == name) then
- local iname = nil
- local name,ox,oy,iname = parts[1],tonumber(parts[2]),tonumber(parts[3]),parts[4]
- image = paintutils.loadImage(iname)
- term.setCursorPos(10,1)
- term.setBackgroundColor(colors.black)
- for i=ox,ox+getWidth(image) do
- for g=oy,oy+getHeight(image) do
- if (pixels[i..g] ~= nil) then
- term.setCursorPos(i,g)
- term.setBackgroundColor(pixels[i..g])
- term.write(" ")
- else
- term.setCursorPos(i,g)
- term.setBackgroundColor(bg)
- term.write(" ")
- end
- end
- end
- paintutils.drawImage(image,x,y)
- table.remove(sprites,h)
- table.insert(sprites,name..";"..x..";"..y..";"..iname)
- else
- end
- end
- return false
- end
- function getSpriteColider(name)
- for h=1,#sprites do
- local parts = {}
- term.setBackgroundColor(colors.black)
- for word in string.gmatch(sprites[h],"[^;]+") do
- table.insert(parts,word)
- end
- if (parts[1] == name) then
- local iname = nil
- local name,ox,oy,iname = parts[1],tonumber(parts[2]),tonumber(parts[3]),parts[4]
- image = paintutils.loadImage(iname)
- local sizet = {}
- sizet.x = ox
- sizet.y = oy
- sizet.x2 = ox + getWidth(image)
- sizet.y2 = oy + getHeight(image)
- return sizet
- else
- end
- end
- return false
- end
- -- FUNC
- function limitRead(limX, rChar,color,colorb)
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.setCursorBlink(true)
- local origX, origY = term.getCursorPos()
- local returnString = ""
- while true do
- local xPos, yPos = term.getCursorPos()
- local event, p1, p2 = os.pullEvent()
- if event == "char" then
- returnString = returnString..p1
- if not rChar then
- if not limX then
- write(p1)
- else
- if string.len(returnString) >= limX then
- term.setCursorPos(origX, origY)
- write(string.sub(returnString, (string.len(returnString)-limX)+1))
- elseif string.len(returnString) < limX then
- write(p1)
- end
- end
- else
- if not limX then
- write(rChar)
- else
- if string.len(returnString) >= limX then
- term.setCursorPos(origX, origY)
- write(string.rep(rChar, limX))
- elseif string.len(returnString) < limX then
- write(rChar)
- end
- end
- end
- elseif event == "key" and p1 == 259 then --backspace
- returnString = string.sub(returnString, 1, (string.len(returnString))-1)
- term.setCursorPos(xPos-1,yPos)
- write(" ")
- term.setCursorPos(origX, origY)
- if string.len(returnString) >= limX then
- if not rChar then
- write(string.sub(returnString, (string.len(returnString)-limX)+1))
- else
- write(string.rep(rChar,limX))
- end
- else
- if not rChar then
- write(returnString)
- else
- write(string.rep(rChar, string.len(returnString)))
- end
- end
- elseif event == "key" and p1 == 257 then --enter
- break
- end
- end
- term.setCursorBlink(false)
- return returnString
- end
- function getHeight( image )
- --# init the image start and end variables, these are what track where the start and end are
- local imgStart = #image --# we need to start at the end so we can apply math.min
- local imgEnd = 0 --# we need to start at the start so we can apply math.max
- --# loop through the table
- for index,imageLine in ipairs(image) do
- --# create a variable to hold if the line has a pixel
- local isLine = false
- --# loop through the pixels in the line
- for i,pixel in ipairs(imageLine) do
- --# if the pixel is drawable
- if pixel ~= 0 then
- --# record that there is a pixel, and exit the loop, no need to check anymore, we know there is at least 1
- isLine = true
- break
- end
- end
- --# if the line has pixels, check if its the start or end
- if isLine then
- imgStart = math.min(imgStart,index)
- imgEnd = math.max(imgEnd,index)
- end
- end
- --# return the height of the image, which is the end plus the start, plus 1 because tables start at index 1 not 0
- return imgEnd - imgStart + 1
- end
- function getWidth(img)
- --# the max width
- local maxWidth = 0
- --# loop through the image
- for i,line in pairs(img) do
- --# the variable to hold where the line starts
- local lineStart = #line --# start it at the end so we can apply math.min
- --# the variable to hold where the line ends
- local lineEnd = 0 --# start at the start so we can apply math.max
- --# loop the line
- for index,v in pairs(line) do
- --# if its a pixel
- if v ~= 0 then
- --# check if its the start or the end of the line
- lineStart = math.min(lineStart,index)
- lineEnd = math.max(lineEnd,index)
- end
- end
- --# the length of the line is the end minus the start positions, +1 because tables start at index 1 not 0
- local length = lineEnd - lineStart + 1
- --# check if its the max length
- maxWidth = math.max(maxWidth, length)
- end
- --# return the max length
- return maxWidth
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement