Guest User

Calc

a guest
Mar 26th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.81 KB | None | 0 0
  1. --Calculator
  2. x4 = 25
  3. x4 = x4 + 0
  4. slc2 = 0
  5. op = 0
  6. Eingabe = {}
  7.  
  8. function titlebarTaschenrechner()
  9.  term.setCursorPos(1,1)
  10.  term.setBackgroundColor(16385)
  11.  term.setTextColor(1)
  12.  term.clearLine()
  13.  term.setCursorPos(2,1)
  14.  print("[Close]")
  15. end
  16.  
  17. function TaschenrechnerButtonsEinzeln(i,x2,y2)
  18.  num = i
  19.  term.setBackgroundColor(256)
  20.  term.setTextColor(32768)
  21.  term.setCursorPos(x2, y2)
  22.  print("   ")
  23.  term.setCursorPos(x2, y2+1)
  24.  write(" ")
  25.  term.setBackgroundColor(1)
  26.  write(num)
  27.  term.setBackgroundColor(256)
  28.  write(" ")
  29.  term.setCursorPos(x2, y2+2)
  30.  print("   ")
  31. end
  32.  
  33. function TaschenrechnerOperatoren(i2,x3,y3)
  34.  op = i2
  35.  term.setCursorPos(x3,y3)
  36.  term.setBackgroundColor(256)
  37.  term.setTextColor(32768)
  38.  print("          ")
  39.  term.setCursorPos(x3,y3+1)
  40.  write(" ")
  41.  term.setCursorPos(x3+1,y3+1)
  42.  term.setBackgroundColor(1)
  43.  write(op)
  44.  term.setCursorPos(x3+9,y3+1)
  45.  term.setBackgroundColor(256)
  46.  write(" ")
  47.  term.setCursorPos(x3, y3+2)
  48.  print("          ")
  49.  
  50.  
  51. end
  52.  
  53. function TaschenrechnerButtonsGesamt()          --()
  54.  TaschenrechnerButtonsEinzeln(1,2,3)
  55.  TaschenrechnerButtonsEinzeln(2,6,3)  
  56.  TaschenrechnerButtonsEinzeln(3,10,3)
  57.  TaschenrechnerButtonsEinzeln(4,2,7)
  58.  TaschenrechnerButtonsEinzeln(5,6,7)
  59.  TaschenrechnerButtonsEinzeln(6,10,7)
  60.  TaschenrechnerButtonsEinzeln(7,2,11)
  61.  TaschenrechnerButtonsEinzeln(8,6,11)
  62.  TaschenrechnerButtonsEinzeln(9,10,11)
  63.  TaschenrechnerButtonsEinzeln(0,2,15)
  64.  TaschenrechnerButtonsEinzeln("C",6,15)
  65.  TaschenrechnerButtonsEinzeln(">",10,15)
  66.  term.setBackgroundColor(256)
  67.  term.setTextColor(32768)
  68.  term.setCursorPos(24, 3)
  69.  print("                      ")
  70.  term.setCursorPos(24,4)
  71.  write(" ")
  72.  term.setBackgroundColor(1)
  73.  write("                    ")
  74.  term.setBackgroundColor(256)
  75.  write(" ")    
  76.  term.setCursorPos(24,5)
  77.  print("                      ")
  78.  TaschenrechnerOperatoren("add     ", 24, 9)
  79.  TaschenrechnerOperatoren("subtract", 36,9)
  80.  TaschenrechnerOperatoren("multiply", 24, 14)
  81.  TaschenrechnerOperatoren("divide  ", 36, 14)
  82. end
  83.  
  84. function TaschenrechnerErg(i)
  85.   i = x4
  86.  if x4 <= 43 then
  87.   x4 = x4 +1
  88.  elseif x4 >= 43 then
  89.   x4 = x4
  90.  end  
  91. end
  92.  
  93.  
  94. function TaschenrechnerVorspann()
  95.  term.setBackgroundColor(8)
  96.  term.setTextColor(16384)
  97.  shell.run("clear")
  98.  term.setCursorPos(16 , 10)
  99.  print("    Calculator     ")
  100.  term.setCursorPos(16,11)
  101.  print("--written by Vali--")
  102. end
  103.  
  104. function TaschenrechnerZahlen(i,x)
  105.  table.insert(Eingabe, i)
  106.  term.setBackgroundColor(1)
  107.  term.setTextColor(32768)
  108.  term.setCursorPos(x,4)
  109.  TaschenrechnerErg(x)
  110.  write(Eingabe)
  111.  end
  112.  
  113. function TaschenrechnerOPclear()
  114. term.setBackgroundColor(1)
  115. term.setTextColor(32768)
  116. term.setCursorPos( 25, 4)
  117. write("                        ")
  118. term.setCursorPos(25, 4)
  119. end
  120.  
  121. TaschenrechnerVorspann()
  122. sleep(2)
  123. shell.run("clear")
  124. TaschenrechnerButtonsGesamt()
  125. titlebarTaschenrechner()
  126.  
  127.  
  128. while true do
  129. local event, button, x, y = os.pullEvent()
  130.  if event == "mouse_click" then
  131.   if x >= 2 and x <= 8 and y == 1 and button == 1 then
  132.      shell.run("GUI")
  133.    elseif x >= 2 and x <= 4 and y >= 3 and y <= 5 and button == 1 then
  134.      TaschenrechnerZahlen(1, x4)
  135.    elseif x >= 6 and x <= 8 and y >= 3 and y <= 5 and button == 1 then
  136.      TaschenrechnerZahlen(2, x4)
  137.    elseif x >= 10 and x <= 12 and y >= 3 and y <= 5 and button == 1 then
  138.      TaschenrechnerZahlen(3, x4)
  139.    elseif x >= 2 and x <= 4 and y >=7 and y <= 9 and button == 1 then
  140.      TaschenrechnerZahlen(4, x4)
  141.    elseif x >= 6 and x <= 8 and y >= 7 and y <= 9 and button == 1 then
  142.      TaschenrechnerZahlen(5, x4)
  143.    elseif x >10 and x <= 12 and y >= 7 and y <= 9 and button == 1 then
  144.      TaschenrechnerZahlen(6, x4)
  145.    elseif x >= 2 and x <= 4 and y >= 11 and y <= 13 and button == 1 then
  146.      TaschenrechnerZahlen(7, x4)
  147.    elseif x >= 6 and x <= 8 and y >= 11 and y <= 13 and button == 1 then
  148.      TaschenrechnerZahlen(8, x4)
  149.    elseif x >= 10 and x <= 12 and y >= 11 and y <= 13 and button == 1 then
  150.      TaschenrechnerZahlen(9, x4)
  151.    elseif x >= 2 and x <= 4 and y >= 15 and y <= 17 and button == 1 then
  152.      TaschenrechnerZahlen(0, x4)        
  153.    elseif x >= 24 and x <= 34 and y >= 9 and y <= 11 and button == 1 and slc2 == 0 then
  154.      TaschenrechnerZahlen("+", x4)
  155.      slc2 = 1  
  156.      op = 1
  157.    elseif x >= 36 and x <= 46 and y >= 9 and y <= 11 and button == 1 and slc2 == 0 then
  158.      TaschenrechnerZahlen("-", x4)
  159.      slc2 = 1
  160.      op = 2
  161.    elseif x >= 24 and y <= 34 and y >= 14 and y <= 16 and button == 1 and slc2 == 0 then
  162.      TaschenrechnerZahlen("*", x4)
  163.      slc2 = 1
  164.      op = 3
  165.    elseif x >= 36 and x <= 46 and y >= 14 and y <= 16 and button == 1 and slc2 == 0 then
  166.      TaschenrechnerZahlen("/", x4)
  167.      slc2 = 1
  168.      op = 4
  169.    
  170.    elseif x >= 6 and x <= 8 and y >= 15 and y <= 17 and buttons == 1 then
  171.     TaschenrechnerOPclear()
  172.       end
  173.      end
  174.     end
Advertisement
Add Comment
Please, Sign In to add comment