Advertisement
Guest User

weatherswitch

a guest
Mar 17th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.13 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local gpu = component.gpu
  4. local redstone = component.redstone
  5. local unicode = require("unicode")
  6. local term = require("term")
  7.  
  8. function funcbutton1()
  9.  
  10. redstone.setOutput(3, 1)
  11. os.sleep(1)
  12. redstone.setOutput(3, 0)
  13.  
  14. end
  15.  
  16. function funcbutton2()
  17.  
  18. redstone.setOutput(0, 1)
  19. os.sleep(1)
  20. redstone.setOutput(0, 0)
  21.  
  22. end
  23.  
  24. buttons = {button1 = {x = 1, y = 1, width = 10 , heigh = 5, text = "ясно", color = 0x0000ff, func = funcbutton1},
  25. button2 = {x = 12, y = 1, width = 10, heigh = 5, text = "дождь", color = 0x0000ff, func = funcbutton2}
  26. }
  27.  
  28. function drawbuttons()
  29.  
  30. for k, v in pairs(buttons) do
  31.  
  32.  
  33. gpu.setBackground(v.color)
  34.  
  35. gpu.fill(v.x, v.y, v.width, v.heigh, " ")
  36. gpu.set(v.x + v.width/ 2 - unicode.wlen(v.text) / 2, v.y + v.heigh / 2, v.text)
  37. end
  38.  
  39. --gpu.setbackground(0x000000, false)
  40.  
  41. end
  42.  
  43. function ev()
  44.  
  45. while true do
  46. local _,_,x,y = event.pull("touch")
  47.  
  48. for k,v in pairs(buttons) do
  49. if x >= v.x and x < v.x + v.width+2 and y >= v.y and y < v.y + v.heigh then
  50. v.func()
  51.  
  52. end
  53. end
  54. end
  55. end
  56.  
  57. term.clear()
  58.  
  59.  
  60. drawbuttons()
  61. ev()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement