Advertisement
paramus

Calculator

Feb 11th, 2025 (edited)
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.92 KB | Gaming | 0 0
  1. local Total, Operando = 0, ""
  2.  
  3. function Gui()
  4.     term.setBackgroundColor(colors.black)
  5.     term.clear()
  6.    
  7.     term.setCursorPos(1,1)
  8.     term.write(Total)
  9.     term.setCursorPos(1,2)
  10.     term.write(Operando)
  11.    
  12.     --remove when done
  13.     paintutils.drawLine(27,1,27,20,colors.white)
  14.    
  15.     --Number buttons
  16.     paintutils.drawFilledBox(1,4,5,7,colors.yellow)
  17.     term.setCursorPos(3,6)
  18.     term.write("7")
  19.     paintutils.drawFilledBox(6,4,10,7,colors.yellow)
  20.     term.setCursorPos(8,6)
  21.     term.write("8")
  22.     paintutils.drawFilledBox(11,4,15,7,colors.yellow)
  23.     term.setCursorPos(13,6)
  24.     term.write("9")
  25.     paintutils.drawFilledBox(1,8,5,11,colors.yellow)
  26.     term.setCursorPos(3,10)
  27.     term.write("4")
  28.     paintutils.drawFilledBox(6,8,10,11,colors.yellow)
  29.     term.setCursorPos(8,10)
  30.     term.write("5")
  31.     paintutils.drawFilledBox(11,8,15,11,colors.yellow)
  32.     term.setCursorPos(13,10)
  33.     term.write("6")
  34.     paintutils.drawFilledBox(1,12,5,15,colors.yellow)
  35.     term.setCursorPos(3,14)
  36.     term.write("1")
  37.     paintutils.drawFilledBox(6,12,10,15,colors.yellow)
  38.     term.setCursorPos(8,14)
  39.     term.write("2")
  40.     paintutils.drawFilledBox(11,12,15,15,colors.yellow)
  41.     term.setCursorPos(13,14)
  42.     term.write("3")
  43.     paintutils.drawFilledBox(1,16,5,19,colors.yellow)
  44.     term.setCursorPos(3,18)
  45.     term.write("")
  46.     paintutils.drawFilledBox(6,16,10,19,colors.yellow)
  47.     term.setCursorPos(8,18)
  48.     term.write("0")
  49.     paintutils.drawFilledBox(11,16,15,19,colors.yellow)
  50.     term.setCursorPos(13,18)
  51.     term.write(",")
  52.    
  53.     --Operators Buttons
  54.     paintutils.drawFilledBox(16,4,20,7,colors.gray)
  55.     term.setCursorPos(18,6)
  56.     term.write("/")
  57.     paintutils.drawFilledBox(21,4,26,7,colors.gray)
  58.     term.setCursorPos(23,6)
  59.     term.write("CE")
  60.     paintutils.drawFilledBox(16,8,20,11,colors.gray)
  61.     term.setCursorPos(18,10)
  62.     term.write("*")
  63.     paintutils.drawFilledBox(21,8,26,11,colors.gray)
  64.     term.setCursorPos(23,10)
  65.     term.write("+")
  66.     paintutils.drawFilledBox(16,12,20,15,colors.gray)
  67.     term.setCursorPos(18,14)
  68.     term.write("-")
  69.     paintutils.drawFilledBox(21,12,26,15,colors.gray)
  70.     term.setCursorPos(23,14)
  71.     term.write("")
  72.     paintutils.drawFilledBox(16,16,20,19,colors.gray)
  73.     term.setCursorPos(18,18)
  74.     term.write("%")
  75.     paintutils.drawFilledBox(21,16,26,19,colors.gray)
  76.     term.setCursorPos(23,18)
  77.     term.write("=")
  78. end
  79.  
  80. -- Main --
  81. while (true) do
  82.     Gui()
  83.     term.setCursorPos(1,1)
  84.     local e, b, x,y = os.pullEvent()
  85.     if (e == "key") then
  86.         local key = keys.getName(b)
  87.        
  88.         if (key == "+") then
  89.             operando = "+"
  90.         elseif (key == "-") then
  91.             operando = "-"
  92.         elseif (key == "*") then
  93.             operando = "*"
  94.         elseif (key == "/") then
  95.             operando = "/"
  96.         else
  97.             if (keys.getName(b) == "zero") then key = "0"
  98.             elseif (keys.getName(b) == "one") then key = "1"
  99.             elseif (keys.getName(b) == "two") then key = "2"
  100.             elseif (keys.getName(b) == "three") then key = "3"
  101.             elseif (keys.getName(b) == "four") then key = "4"
  102.             elseif (keys.getName(b) == "five") then key = "5"
  103.             elseif (keys.getName(b) == "six") then key = "6"
  104.             elseif (keys.getName(b) == "seven") then key = "7"
  105.             elseif (keys.getName(b) == "eight") then key = "8"
  106.             elseif (keys.getName(b) == "nine") then key = "9"
  107.             end
  108.  
  109.             if (Operando == "") then
  110.                 Total = tonumber(key)
  111.             elseif (Operando == "+") then
  112.                 Total = Total + tonumber(key)
  113.             elseif (Operando == "-") then
  114.                 Total = Total - tonumber(key)
  115.             elseif (Operando == "*") then
  116.                 Total = Total * tonumber(key)
  117.             elseif (Operando == "/") then
  118.                 Total = Total / tonumber(key)
  119.             end
  120.         end
  121.     end
  122. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement