MegiRicky

recieverGunImagingSys

Jul 26th, 2024 (edited)
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. local modem = peripheral.find("modem")
  2. local monitor = peripheral.find("monitor")
  3. local imageChannel = 600
  4. local controlChannel = 601
  5. local distanceChannel = 604
  6. local distance = 0
  7.  
  8. modem.open(imageChannel)
  9. modem.open(distanceChannel)
  10.  
  11. local function hexColorFromCode(code)
  12. local colors = {
  13. ["0"] = "000000", -- Black
  14. ["1"] = "0000AA", -- Dark Blue
  15. ["2"] = "00AA00", -- Dark Green
  16. ["3"] = "00AAAA", -- Dark Aqua
  17. ["4"] = "AA0000", -- Dark Red
  18. ["5"] = "AA00AA", -- Dark Purple
  19. ["6"] = "FFAA00", -- Gold
  20. ["7"] = "AAAAAA", -- Gray
  21. ["8"] = "555555", -- Dark Gray
  22. ["9"] = "5555FF", -- Blue
  23. ["a"] = "55FF55", -- Green
  24. ["b"] = "55FFFF", -- Aqua
  25. ["c"] = "FF5555", -- Red
  26. ["d"] = "FF55FF", -- Light Purple
  27. ["e"] = "FFFF55", -- Yellow
  28. ["f"] = "FFFFFF", -- White
  29. }
  30. return colors[code] or "000000"
  31. end
  32.  
  33. monitor.setTextScale(0.5)
  34. monitor.clear()
  35. local width, height = monitor.getSize()
  36.  
  37. local function render(data)
  38. local mirroredX = width - data[1] + 1
  39. monitor.setCursorPos(mirroredX, data[2])
  40.  
  41. -- Check if the position is the center of the screen
  42. if mirroredX == math.floor(width / 2) + 1 and data[2] == math.floor(height / 2) then
  43. -- Render crosshair "o" without changing the background color
  44. monitor.blit("o", "f", data[5])
  45. else
  46. monitor.blit(data[3], data[4], data[5])
  47. end
  48. end
  49.  
  50. local function receiving()
  51. while true do
  52. local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  53. if channel == imageChannel then
  54. render(message)
  55. elseif channel == distanceChannel then
  56. distance = message
  57. end
  58. monitor.setCursorPos(1, 1)
  59. monitor.write("- / +".." ".."TR:"..math.floor(distance))
  60. end
  61. end
  62.  
  63. local function handleTouch()
  64. while true do
  65. local event, side, x, y = os.pullEvent("monitor_touch")
  66. if y == 1 and x == 1 then
  67. modem.transmit(controlChannel,0,0.1)
  68. print("decreasing")
  69. elseif y == 1 and x == 5 then
  70. modem.transmit(controlChannel,0,-0.1)
  71. print("increasing")
  72. else
  73. modem.transmit(controlChannel,0,0)
  74. end
  75. end
  76. end
  77.  
  78. parallel.waitForAny(
  79. receiving,
  80. handleTouch
  81. )
  82.  
  83. --pastebin get pmVGr75S recieverGunImagingSys.lua
  84. --pastebin run pmVGr75S
Advertisement
Add Comment
Please, Sign In to add comment