Guest User

butt

a guest
Jul 31st, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.15 KB | None | 0 0
  1. monSide = "right"
  2.  
  3. --lime/red will toggle
  4. --blue/gray/magenta will NOT change colour.
  5.  
  6. --add buttons here
  7. tButtons = {
  8. --name, xmin, xmax, ymin, ymax, Colour
  9. {"Button1",1,10,1,3,"lime"},
  10. {"Button2",12,21,1,3,"lime"},
  11. {"Button3",1,10,5,7,"lime"},
  12. {"Button4",12,21,5,7,"magenta"},
  13. {"Button5",1,10,9,11,"gray"},
  14. {"Button6",12,21,9,11,"blue"},
  15. }
  16.  
  17. --add function here
  18. function userInput(Touch)
  19. if Touch == 1 then
  20.     print("1")
  21. elseif Touch == 2 then
  22.     print("2")
  23. elseif Touch == 3 then
  24.     print("3")
  25. elseif Touch == 4 then
  26.     print("4")
  27. elseif Touch == 5 then
  28.     print("soooooo boring")
  29. elseif Touch == 6 then
  30.     print("i'm blue baby!")
  31. end
  32. end
  33.  
  34. ------------------------------------------------
  35.  
  36.  
  37.  
  38. function drawButtons()
  39. mon.setBackgroundColour(colours.black)
  40. mon.clear()
  41.  
  42.  
  43. for i = 1,#tButtons do
  44.     if tButtons[i][6] == "red" then
  45.         mon.setBackgroundColor(colorRed)
  46.     elseif tButtons[i][6] == "lime" then
  47.         mon.setBackgroundColor(colorLime)
  48.     elseif tButtons[i][6] == "blue" then
  49.         mon.setBackgroundColor(colorBlue)
  50.     elseif tButtons[i][6] == "gray" then
  51.         mon.setBackgroundColor(colorGray)
  52.     elseif tButtons[i][6] == "magenta" then
  53.         mon.setBackgroundColor(colorMagenta)
  54.    
  55.     end
  56.         for i2 = tButtons[i][4],tButtons[i][5] do
  57.             for i3 = tButtons[i][2],tButtons[i][3] do
  58.                 mon.setCursorPos(i3,i2)
  59.                 mon.write(" ")
  60.             end
  61.         end
  62.     mon.setCursorPos((tButtons[i][2] + tButtons[i][3]) /2 -(#tButtons[i][1]/2 -1 ), (tButtons[i][4] + tButtons[i][5])/2 )
  63.     mon.write(tButtons[i][1])
  64.     end
  65. end
  66.  
  67. mon = peripheral.wrap(monSide)
  68. mon.setBackgroundColour(colours.black)
  69. mon.clear()
  70.  
  71. colorRed = 16384
  72. colorLime = 32
  73. colorBlue = 2048
  74. colorGray = 256
  75. colorMagenta = 4
  76.  
  77. function miceClick()
  78. event, button, miceX, miceY = os.pullEvent("monitor_touch")
  79.     for i4 = 1,#tButtons do
  80.  
  81.         if miceX >= tButtons[i4][2] and miceX <= tButtons[i4][3] and miceY >= tButtons[i4][4] and miceY <= tButtons[i4][5] then
  82.             if tButtons[i4][6] == "lime" then
  83.                 tButtons[i4][6] = "red"
  84.             elseif tButtons[i4][6] == "red" then
  85.                 tButtons[i4][6] = "lime"
  86.             end
  87.                 Touch = i4
  88.                 userInput(Touch)
  89.         end
  90.     end
  91. end
  92.  
  93.    
  94. while true do
  95. drawButtons()
  96. miceClick()
  97. end
Advertisement
Add Comment
Please, Sign In to add comment