Advertisement
JMANN2400

Calculator

Aug 18th, 2017
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.38 KB | None | 0 0
  1.  
  2.  
  3.  
  4. numbers = {}
  5.  
  6. function checkNumber(xmin,ymin,xmax,ymax,output)
  7.     local event, button, x, y = os.pullEvent()
  8.     if event == "mouse_click" and button == 1 then
  9.         if x >= xmin and x <= xmax and y >= ymin and y <= ymax then
  10.             table.insert(numbers, output)
  11.         end
  12.     end
  13. end
  14.  
  15. function keypad()
  16.     checkNumber(3,13,5,13,1)
  17.     checkNumber(8,13,10,13,2)
  18.     checkNumber(13,13,14,13,3)
  19.     checkNumber(3,11,5,11,4)
  20.     checkNumber(8,11,10,11,5)
  21.     checkNumber(13,11,14,11,6)
  22.     checkNumber(3,9,5,9,7)
  23.     checkNumber(8,9,10,9,8)
  24.     checkNumber(13,9,14,9,9)
  25.     checkNumber(3,15,10,15,0)
  26. end
  27.  
  28. function displayScreen()
  29.     print("+------------------------+")
  30.     print("|+----------------------+|")
  31.     print("||                      ||")
  32.     print("|+---++---++--++---++---+|")
  33.     print("||MC ||MR ||MS||M+ ||M- ||")
  34.     print("|+---++---++--++---++---+|")
  35.     print("||<--||CE ||C ||+/-||SRT||")
  36.     print("|+---++---++--++---++---+|")          
  37.     print("|| 7 || 8 ||9 || / || % ||")
  38.     print("|+---++---++--++---++---+|")        
  39.     print("|| 4 || 5 ||6 || * ||1/X||")
  40.     print("|+---++---++--++---++---+|")        
  41.     print("|| 1 || 2 ||3 || - ||   ||")
  42.     print("|+---++---++--++---+| = ||")
  43.     print("||   0    ||. || + ||   ||")
  44.     print("|+---++---++--++---++---+|")
  45.     print("+------------------------+")
  46.     print("")
  47.     print("")
  48. end
  49. displayScreen()
  50. while true do
  51.     keypad()
  52.     term.setCursorPos(3,3)
  53.     term.write(numbers[1])
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement