Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.setTextColor(colors.white)
- local button = {}
- term.setBackgroundColor(colors.black)
- function CurPos()
- term.setCursorPos(4,4)
- end
- function drawCalc()
- term.clear()
- term.setCursorPos(2,2)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- function printVerticalLine(lineX, startingY, endingY, lineColor)
- local curX, curY = term.getCursorPos()
- term.setBackgroundColor(lineColor)
- for lineY = startingY, endingY do
- term.setCursorPos(lineX, lineY)
- term.write(" ")
- end
- term.setCursorPos(curX, curY)
- end
- function printHorizontalLine(yLine, startingX, endingX, lineColor)
- local curX, curY = term.getCursorPos()
- term.setBackgroundColor(lineColor)
- for xLine = startingX, endingX do
- term.setCursorPos(xLine, yLine)
- term.write(" ")
- end
- term.setCursorPos(curX, curY)
- end
- printVerticalLine(2,2,18, colors.white)
- --Left Border
- printHorizontalLine(2,2,20, colors.white)
- --Top
- printHorizontalLine(6,2, 20 , colors.white)
- --Upper Before Keys
- printVerticalLine(20,2,18, colors.white)
- --Right Border
- printHorizontalLine(18,2,20, colors.white)
- --Bottom
- printVerticalLine(8,6,18, colors.white)
- --Left Seperator
- printVerticalLine(14,6,18,colors.white)
- --Right Seperator
- printHorizontalLine(10,2,20,colors.white)
- --Upper Seperator
- printHorizontalLine(14,2,20,colors.white)
- --Lower Seperator
- end
- function setTable(name, func, xmin, xmax, ymin, ymax)
- button[name] = {}
- button[name]["func"] = func
- button[name]["active"] = false
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["xmax"] = xmax
- button[name]["ymax"] = ymax
- end
- function fillTable()
- setTable("1",One,3,7,15,17)
- setTable("2",Two,9,13,15,17)
- setTable("3",Three,15,19,15,17)
- setTable("4",Four,3,7,11,13)
- setTable("5",Five,9,13,11,13)
- setTable("6",Six,15,19,11,13)
- setTable("7",Seven, 3,7,7,9)
- setTable("8",Eight, 9,13,7,9)
- setTable("9",Nine, 15,19,7,9)
- end
- function fill(text, color, bData)
- term.setBackgroundColor(color)
- local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
- local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
- for j = bData["ymin"], bData["ymax"] do
- term.setCursorPos(bData["xmin"], j)
- if j == yspot then
- for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
- if k == xspot then
- term.write(text)
- else
- term.write(" ")
- end
- end
- else
- for i = bData["xmin"], bData["xmax"] do
- term.write(" ")
- end
- end
- end
- term.setBackgroundColor(colors.black)
- end
- function screen()
- local currColor
- for name,data in pairs(button) do
- local on = data["active"]
- if on == true then
- currColor = colors.gray
- else
- currColor = colors.black
- end
- fill(name, currColor, data)
- end
- end
- function checkxy(x, y)
- for name, data in pairs(button) do
- if y>=data["ymin"] and y <= data["ymax"] and x>=data["xmin"] and x<= data["xmax"] then
- term.setCursorPos(1, 1)
- write(name)
- data["active"] = not data["active"]
- sleep(0.1)
- data["active"] = not data["active"]
- return true, name
- end
- end
- return false, nil
- end
- calc = ""
- drawCalc()
- fillTable()
- screen()
- while true do
- local e,button,x,y = os.pullEvent("mouse_click")
- bValid, numb = checkxy(x,y)
- if bValid then
- calc = calc .. numb
- term.setCursorPos(4, 4)
- if #calc < 14 then
- write(calc)
- else
- write(calc:sub(#calc-14))
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment