Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Total, Memory, Operando = 0, 0, ""
- function Gui()
- term.setBackgroundColor(colors.black)
- term.clear()
- if (Memory ~= 0) then
- term.setCursorPos(1,1)
- term.write(Memory)
- end
- term.setCursorPos(1,2)
- term.write(Operando)
- term.setCursorPos(1,3)
- term.write(Total)
- --remove when done
- paintutils.drawLine(27,1,27,20,colors.white)
- --Number buttons
- paintutils.drawFilledBox(1,4,5,7,colors.yellow)
- term.setCursorPos(3,6)
- term.write("7")
- paintutils.drawFilledBox(6,4,10,7,colors.orange)
- term.setCursorPos(8,6)
- term.write("8")
- paintutils.drawFilledBox(11,4,15,7,colors.yellow)
- term.setCursorPos(13,6)
- term.write("9")
- paintutils.drawFilledBox(1,8,5,11,colors.orange)
- term.setCursorPos(3,10)
- term.write("4")
- paintutils.drawFilledBox(6,8,10,11,colors.yellow)
- term.setCursorPos(8,10)
- term.write("5")
- paintutils.drawFilledBox(11,8,15,11,colors.orange)
- term.setCursorPos(13,10)
- term.write("6")
- paintutils.drawFilledBox(1,12,5,15,colors.yellow)
- term.setCursorPos(3,14)
- term.write("1")
- paintutils.drawFilledBox(6,12,10,15,colors.orange)
- term.setCursorPos(8,14)
- term.write("2")
- paintutils.drawFilledBox(11,12,15,15,colors.yellow)
- term.setCursorPos(13,14)
- term.write("3")
- paintutils.drawFilledBox(1,16,5,19,colors.orange)
- term.setCursorPos(3,18)
- term.write("")
- paintutils.drawFilledBox(6,16,10,19,colors.yellow)
- term.setCursorPos(8,18)
- term.write("0")
- paintutils.drawFilledBox(11,16,15,19,colors.orange)
- term.setCursorPos(13,18)
- term.write(",")
- --Operators Buttons
- paintutils.drawFilledBox(16,4,20,7,colors.gray)
- term.setCursorPos(18,6)
- term.write("/")
- paintutils.drawFilledBox(21,4,26,7,colors.lightGray)
- term.setCursorPos(23,6)
- term.write("<<")
- paintutils.drawFilledBox(16,8,20,11,colors.lightGray)
- term.setCursorPos(18,10)
- term.write("*")
- paintutils.drawFilledBox(21,8,26,11,colors.gray)
- term.setCursorPos(23,10)
- term.write("CE")
- paintutils.drawFilledBox(16,12,20,15,colors.gray)
- term.setCursorPos(18,14)
- term.write("-")
- paintutils.drawFilledBox(21,12,26,15,colors.lightGray)
- term.setCursorPos(23,14)
- term.write("+")
- paintutils.drawFilledBox(16,16,20,19,colors.lightGray)
- term.setCursorPos(18,18)
- term.write("%")
- paintutils.drawFilledBox(21,16,26,19,colors.gray)
- term.setCursorPos(23,18)
- term.write("=")
- end
- function KeyPress(key)
- key = keys.getName(key)
- if (key == "+") then
- operando = "+"
- elseif (key == "-") then
- operando = "-"
- elseif (key == "*") then
- operando = "*"
- elseif (key == "/") then
- operando = "/"
- else
- if (key == "zero") then key = "0"
- elseif (key == "one") then key = "1"
- elseif (key == "two") then key = "2"
- elseif (key == "three") then key = "3"
- elseif (key == "four") then key = "4"
- elseif (key == "five") then key = "5"
- elseif (key == "six") then key = "6"
- elseif (key == "seven") then key = "7"
- elseif (key == "eight") then key = "8"
- elseif (key == "nine") then key = "9"
- end
- if (Operando == "") then
- if (Total == 0) then
- Total = tonumber(key)
- else
- Total = Total .. tonumber(key)
- end
- elseif (Operando == "+") then
- Total = Total + tonumber(key)
- elseif (Operando == "-") then
- Total = Total - tonumber(key)
- elseif (Operando == "*") then
- Total = Total * tonumber(key)
- elseif (Operando == "/") then
- Total = Total / tonumber(key)
- end
- end
- end
- function Click(x,y)
- -- Numbers
- if (x>=1 and x<=5 and y>=4 and y<=7) then
- if (Total == 0) then
- Total = 7
- else
- Total = Total .. 7
- end
- elseif (x>=6 and x<=10 and y>=4 and y<=7) then
- if (Total == 0) then
- Total = 8
- else
- Total = Total .. 8
- end
- elseif (x>=11 and x<=15 and y>=4 and y<=7) then
- if (Total == 0) then
- Total = 9
- else
- Total = Total .. 9
- end
- elseif (x>=1 and x<=5 and y>=8 and y<=11) then
- if (Total == 0) then
- Total = 4
- else
- Total = Total .. 4
- end
- elseif (x>=6 and x<=10 and y>=8 and y<=11) then
- if (Total == 0) then
- Total = 5
- else
- Total = Total .. 5
- end
- elseif (x>=11 and x<=15 and y>=8 and y<=11) then
- if (Total == 0) then
- Total = 6
- else
- Total = Total .. 6
- end
- elseif (x>=1 and x<=5 and y>=12 and y<=15) then
- if (Total == 0) then
- Total = 1
- else
- Total = Total .. 1
- end
- elseif (x>=6 and x<=10 and y>=12 and y<=15) then
- if (Total == 0) then
- Total = 2
- else
- Total = Total .. 2
- end
- elseif (x>=11 and x<=15 and y>=12 and y<=15) then
- if (Total == 0) then
- Total = 3
- else
- Total = Total .. 3
- end
- elseif (x>=6 and x<=10 and y>=16 and y<=19) then
- if (Total == 0) then
- Total = 0
- else
- Total = Total .. 0
- end
- end
- --Symbols
- if (x>=16 and x<=20 and y>=4 and y<=7) then
- Memory = Total
- Total = 0
- Operando = "/"
- elseif (x>=21 and x<=26 and y>=4 and y<=7) then
- local sTotal = tostring(Total)
- Total = tonumber(string.sub(sTotal,1,string.len(sTotal)-1))
- if (Total == nil) then
- Total=0
- end
- elseif (x>=16 and x<=20 and y>=8 and y<=11) then
- Memory = Total
- Total = 0
- Operando = "*"
- elseif (x>=21 and x<=26 and y>=8 and y<=11) then
- Memory = 0
- Total = 0
- Operando = ""
- elseif (x>=16 and x<=20 and y>=12 and y<=15) then
- Memory = Total
- Total = 0
- Operando = "-"
- elseif (x>=21 and x<=26 and y>=12 and y<=15) then
- Memory = Total
- Total = 0
- Operando = "+"
- elseif (x>=16 and x<=20 and y>=16 and y<=19) then
- Memory = Total
- Total = 0
- Operando = "%"
- elseif (x>=21 and x<=26 and y>=16 and y<=19) then
- if (Operando == "+") then
- Total = Memory + Total
- Memory = 0
- Operando = ""
- elseif (Operando == "-") then
- Total = Memory - Total
- Memory = 0
- Operando = ""
- elseif (Operando == "*") then
- Total = Memory * Total
- Memory = 0
- Operando = ""
- elseif (Operando == "/") then
- Total = Memory / Total
- Memory = 0
- Operando = ""
- elseif (Operando == "%") then
- Total = Memory % Total
- Memory = 0
- Operando = ""
- end
- end
- end
- -- Main --
- while (true) do
- Gui()
- term.setCursorPos(1,1)
- parallel.waitForAny(function()
- local event, key, is_held = os.pullEvent("key")
- --KeyPress(key)
- end,
- function()
- local event, button, x, y = os.pullEvent("mouse_click")
- Click(x,y)
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment