Fraeric123

test

Oct 20th, 2025
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | Source Code | 0 0
  1. -- Stručný příklad tlačítka na monitoru
  2. local monitor = peripheral.find("monitor") -- najde připojený monitor
  3. monitor.setTextScale(1)
  4. monitor.setBackgroundColour(colours.black)
  5. monitor.clear()
  6.  
  7. -- Souřadnice tlačítka (x1,y1) - (x2,y2)
  8. local button = {
  9. x1 = 5, y1 = 3,
  10. x2 = 15, y2 = 5,
  11. label = "HELLO"
  12. }
  13.  
  14. -- Funkce na vykreslení tlačítka
  15. local function drawButton()
  16. monitor.setBackgroundColour(colours.blue)
  17. for y = button.y1, button.y2 do
  18. monitor.setCursorPos(button.x1, y)
  19. monitor.write(string.rep(" ", button.x2 - button.x1 + 1))
  20. end
  21. local textX = button.x1 + math.floor((button.x2 - button.x1 - #button.label) / 2)
  22. local textY = math.floor((button.y1 + button.y2) / 2)
  23. monitor.setCursorPos(textX, textY)
  24. monitor.setTextColour(colours.white)
  25. monitor.write(button.label)
  26. end
  27.  
  28. -- Funkce která zkontroluje, jestli klik byl v oblasti tlačítka
  29. local function isInside(x, y)
  30. return x >= button.x1 and x <= button.x2 and y >= button.y1 and y <= button.y2
  31. end
  32.  
  33. drawButton()
  34. monitor.setCursorPos(1,1)
  35. monitor.setTextColour(colours.yellow)
  36. monitor.write("Klikni na tlacitko!")
  37.  
  38. -- Hlavní smyčka
  39. while true do
  40. local event, side, x, y = os.pullEvent("monitor_touch")
  41. if isInside(x, y) then
  42. monitor.setBackgroundColour(colours.green)
  43. monitor.clear()
  44. monitor.setCursorPos(5,3)
  45. monitor.setTextColour(colours.white)
  46. monitor.write("Ahoj! 👋")
  47. sleep(2)
  48. drawButton()
  49. end
  50. end
  51.  
Tags: cc:tweaked OS jsg
Advertisement
Add Comment
Please, Sign In to add comment