Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- buttonsMain = {}
- buttonsExtra = {}
- buttonsColors = {}
- input = {nil, nil, nil}
- calc = ""
- screenX, screenY = term.getSize()
- local color = colors.white
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- function colorSet()
- if name == "White" then
- term.setBackgroundColor(colors.white)
- elseif name == "Orange" then
- term.setBackgroundColor(colors.orange)
- elseif name == "Magenta" then
- term.setBackgroundColor(colors.magenta)
- elseif name == "Light Blue" then
- term.setBackgroundColor(colors.lightBlue)
- elseif name == "Yellow" then
- term.setBackgroundColor(colors.yellow)
- elseif name == "Lime" then
- term.setBackgroundColor(colors.lime)
- elseif name == "Pink" then
- term.setBackgroundColor(colors.pink)
- elseif name == "Gray" then
- term.setBackgroundColor(colors.gray)
- elseif name == "Light Gray" then
- term.setBackgroundColor(colors.lightGray)
- elseif name == "Cyan" then
- term.setBackgroundColor(colors.cyan)
- elseif name == "Purple" then
- term.setBackgroundColor(colors.purple)
- elseif name == "Blue" then
- term.setBackgroundColor(colors.blue)
- elseif name == "Brown" then
- term.setBackgroundColor(colors.brown)
- elseif name == "Green" then
- term.setBackgroundColor(colors.green)
- elseif name == "Red" then
- term.setBackgroundColor(colors.red)
- elseif name == "Black" then
- term.setBackgroundColor(colors.black)
- end
- end
- function printVerticalLine(lineX, startingY, endingY)
- local curX, curY = term.getCursorPos()
- term.setBackgroundColor(colors.white)
- for lineY = startingY, endingY do
- term.setCursorPos(lineX, lineY)
- term.write(" ")
- end
- term.setCursorPos(curX, curY)
- term.setBackgroundColour(colours.black)
- end
- function printHorizontalLine(yLine, startingX, endingX)
- local curX, curY = term.getCursorPos()
- term.setBackgroundColor(colors.white)
- for xLine = startingX, endingX do
- term.setCursorPos(xLine, yLine)
- term.write(" ")
- end
- term.setCursorPos(curX, curY)
- term.setBackgroundColour(colours.black)
- end
- function drawTable()
- printVerticalLine(2,2,18)
- --Left Border
- printVerticalLine(20,2,18)
- --Right Border
- printVerticalLine(8,6,18)
- --Left Seperator
- printVerticalLine(14,6,18)
- --Right Seperator
- printHorizontalLine(2,2,20)
- --Top
- printHorizontalLine(6,2, 20)
- --Upper Before Keys
- printHorizontalLine(18,2,20)
- --Bottom
- printHorizontalLine(10,2,20)
- --Upper Seperator
- printHorizontalLine(14,2,20)
- --Lower Seperator
- term.setBackgroundColor(colors.black)
- end
- function drawFunctionsTable()
- printHorizontalLine(6,32,50)
- --Top
- printHorizontalLine(10,32,50)
- printHorizontalLine(14,32,50)
- printHorizontalLine(18,32,50)
- --Bottom
- printVerticalLine(32,6,18)
- --Left Border
- printVerticalLine(38,6,14)
- printVerticalLine(44,6,18)
- printVerticalLine(50,6,18)
- --Right Border
- term.setBackgroundColor(colors.black)
- end
- function drawColorsTable()
- printVerticalLine(2,2,18)
- --Left
- printVerticalLine(14,2,18)
- printVerticalLine(26,2,18)
- printVerticalLine(40,2,18)
- printVerticalLine(50,2,18)
- end
- function drawExtraButtonsTable()
- --Help, Color settings, 2nd button for filling table with ExtraFunctions
- printVerticalLine(23,6,18)
- --Left Border
- printVerticalLine(29,6,18)
- --Right Border
- printHorizontalLine(6,23,29)
- --Top
- printHorizontalLine(10,23,29)
- printHorizontalLine(14,23,29)
- printHorizontalLine(18,23,29)
- --Bottom
- term.setBackgroundColour(colours.black)
- end
- function setTable(_table, name, xMin, xMax, yMin, yMax)
- table.insert(_table, {
- numb = name,
- xmin = xMin,
- xmax = xMax,
- ymin = yMin,
- ymax = yMax
- })
- end
- function fillTable()
- setTable(buttonsMain, "1", 3, 7, 15, 17)
- setTable(buttonsMain, "2", 9, 13, 15, 17)
- setTable(buttonsMain, "3", 15, 19, 15, 17)
- setTable(buttonsMain, "4", 3, 7, 11, 13)
- setTable(buttonsMain, "5", 9, 13, 11, 13)
- setTable(buttonsMain, "6", 15, 19, 11, 13)
- setTable(buttonsMain, "7", 3, 7, 7, 9)
- setTable(buttonsMain, "8", 9, 13, 7, 9)
- setTable(buttonsMain, "9", 15, 19, 7, 9)
- setTable(buttonsExtra, "1", 3, 7, 15, 17)
- setTable(buttonsExtra, "2", 9, 13, 15, 17)
- setTable(buttonsExtra, "3", 15, 19, 15, 17)
- setTable(buttonsExtra, "4", 3, 7, 11, 13)
- setTable(buttonsExtra, "5", 9, 13, 11, 13)
- setTable(buttonsExtra, "6", 15, 19, 11, 13)
- setTable(buttonsExtra, "7", 3, 7, 7, 9)
- setTable(buttonsExtra, "8", 9, 13, 7, 9)
- setTable(buttonsExtra, "9", 15, 19, 7, 9)
- end
- function fillFunctionsTable()
- setTable(buttonsMain, "C", 33,37,7,9)
- setTable(buttonsMain, ".", 39,43,7,9)
- setTable(buttonsMain, "/", 45,49,7,9)
- setTable(buttonsMain, "+", 33,37,11,13)
- setTable(buttonsMain, "-", 39,43,11,13)
- setTable(buttonsMain, "*", 45,49,11,13)
- setTable(buttonsMain, "0", 33,43,15,17)
- setTable(buttonsMain, "=", 45,49,15,17)
- end
- function fillExtraFunctions()
- setTable(buttonsExtra, "^", 33,37,7,9)
- setTable(buttonsExtra, "rt", 39,43,7,9)
- setTable(buttonsExtra, "/", 45,49,7,9)
- setTable(buttonsExtra, "+", 33,37,11,13)
- setTable(buttonsExtra, "-", 39,43,11,13)
- setTable(buttonsExtra, "*", 45,49,11,13)
- setTable(buttonsExtra, "0", 33,43,15,17)
- setTable(buttonsExtra, "=", 45,49,15,17)
- end
- function fillExtraButtonsTable()
- setTable(buttonsExtra, "F",24,28,7,9)
- setTable(buttonsExtra, "H",24,28,11,13)
- setTable(buttonsExtra, "c",24,28,15,17)
- setTable(buttonsMain, "F",24,28,7,9)
- setTable(buttonsMain, "H",24,28,11,13)
- setTable(buttonsMain, "c",24,28,15,17)
- end
- function fillColorOptions()
- setTable(buttonsColors,"White",3,13,3,5)
- setTable(buttonsColors,"Orange",3,13,7,9)
- setTable(buttonsColors,"Magenta",3,13,11,13)
- setTable(buttonsColors,"Light Blue",3,13,15,17)
- setTable(buttonsColors,"Yellow",15,25,3,5)
- setTable(buttonsColors,"Lime",15,25,7,9)
- setTable(buttonsColors,"Pink",15,25,11,13)
- setTable(buttonsColors,"Gray",15,25,15,17)
- setTable(buttonsColors,"Light Gray",27,37,3,5)
- setTable(buttonsColors,"Cyan",27,37,7,9)
- setTable(buttonsColors,"Purple",27,37,11,13)
- setTable(buttonsColors,"Blue",27,37,15,17)
- setTable(buttonsColors,"Brown",39,49,3,5)
- setTable(buttonsColors,"Green",39,49,7,9)
- setTable(buttonsColors,"Red",39,49,11,13)
- setTable(buttonsColors,"Black",39,49,15,17)
- end
- function checkClick(tab, mx, my)
- for i, v in pairs(tab) do
- if mx >= v.xmin and mx <= v.xmax and my >= v.ymin and my <= v.ymax then
- return true, v.numb
- end
- end
- return false, nil
- end
- function screen(tab)
- term.setBackgroundColour(colours.black)
- term.setTextColour(colours.white)
- for name, data in pairs(tab) do
- local yspot = (data["ymin"] + data["ymax"]) / 2
- local xspot = (data["xmin"] + data["xmax"]) / 2
- term.setCursorPos(xspot, yspot)
- colorSet()
- --should be sets background of the color to its name
- write(data.numb)
- end
- end
- function redraw()
- term.setCursorPos(4, 4)
- write(string.rep(" ", 15))
- term.setCursorPos(4, 4)
- end
- function displayHelp()
- term.setBackgroundColour(colours.white)
- term.setCursorPos(1, 1)
- term.clear()
- term.setBackgroundColour(colours.grey)
- write(string.rep(" ", screenX))
- term.setBackgroundColour(colours.red)
- term.setCursorPos(screenX, 1)
- write("X")
- term.setBackgroundColour(colours.white)
- term.setTextColour(colours.black)
- term.setCursorPos(1, 2)
- print("There will be help here once I decide to not be lazy and fill it out, for now check the forums!")
- repeat local _, but, x, y = os.pullEvent("mouse_click") until but == 1 and x == screenX and y == 1
- term.setBackgroundColour(colours.black)
- term.clear()
- drawTable()
- screen(buttonsMain)
- drawFunctionsTable()
- drawExtraButtonsTable()
- end
- function setInput1()
- input[1] = tonumber(calc) or input[1]
- input[2] = numb
- redraw()
- calc = ""
- numb = ""
- end
- function enterPress()
- input[3] = tonumber(calc)
- redraw()
- calc = ""
- if input[2] == "+" then
- Output = input[1] + input[3]
- elseif input[2] == "-" then
- Output = input[1] - input[3]
- elseif input[2] == "*" then
- Output = input[1] * input[3]
- elseif input[2] == "/" then
- Output = input[1] / input[3]
- elseif input[2] == "^" then
- Output = input[1] ^ input[3]
- elseif input[2] == "rt" then
- Output = math.sqrt(input[1])
- end
- write(Output)
- input[1] = Output
- end
- --[[ Running Code ]]--
- -- Run the functions to fill the table with math functions
- fillExtraFunctions()
- fillTable()
- fillFunctionsTable()
- fillExtraButtonsTable()
- -- Run the functions to draw the tables
- drawTable()
- drawFunctionsTable()
- drawExtraButtonsTable()
- screen(buttonsMain)
- state = "main"
- while true do
- local e, but, x, y = os.pullEvent("mouse_click")
- if but == 1 then
- bValid, numb = checkClick(state == "main" and buttonsMain or state == "extra" and buttonsExtra, x, y)
- if bValid then
- if numb == "+" then
- setInput1()
- elseif numb == "-" then
- setInput1()
- elseif numb == "*" then
- setInput1()
- elseif numb == "/" then
- setInput1()
- elseif numb == "^" then
- setInput1()
- elseif numb == "rt" then
- setInput1()
- elseif numb == "H" then
- displayHelp()
- elseif numb == "F" then
- drawTable()
- drawFunctionsTable()
- drawExtraButtonsTable()
- if state == "main" then
- state = "extra"
- screen(buttonsExtra)
- elseif state == "extra" then
- state = "main"
- screen(buttonsMain)
- end
- elseif numb == "=" then
- enterPress()
- elseif numb == "c" then
- term.clear()
- drawColorsTable()
- screen(buttonsColors)
- if numb == "White" then
- color = colors.white
- elseif numb == "Orange" then
- color = colors.orange
- elseif numb == "Magenta" then
- color = colors.magenta
- elseif numb == "Light Blue" then
- color = colors.lightBlue
- elseif numb == "Yellow" then
- color = colors.yellow
- elseif numb == "Lime" then
- color = colors.lime
- elseif numb == "Pink" then
- color = colors.pink
- elseif numb == "Gray" then
- color = colors.gray
- elseif numb == "Light Gray" then
- color = colors.lightGray
- elseif numb == "Cyan" then
- color = colors.cyan
- elseif numb == "Purple" then
- color = colors.purple
- elseif numb == "Blue" then
- color = colors.blue
- elseif numb == "Brown" then
- color = colors.brown
- elseif numb == "Green" then
- color = colors.green
- elseif numb == "Red" then
- color = colors.red
- elseif numb == "Black" then
- color = colors.black
- end
- term.clear()
- fillExtraFunctions()
- fillTable()
- fillFunctionsTable()
- fillExtraButtonsTable()
- drawTable()
- drawFunctionsTable()
- drawExtraButtonsTable()
- screen(buttonsMain)
- state = "main"
- elseif numb == "C" then
- for i = 1,3 do
- input[i] = nil
- end
- calc = ""
- redraw()
- elseif numb == "." then
- calc = calc .. numb
- term.setCursorPos(4,4)
- if #calc < 14 then
- write(calc)
- else
- write(calc:sub(#calc-14))
- end
- elseif tonumber(numb) then -- if it is a number
- calc = calc .. numb
- term.setCursorPos(4, 4)
- if #calc < 14 then
- write(calc)
- else
- write(calc:sub(#calc-14))
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment