Advertisement
magnasiefr

Untitled

Jun 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.28 KB | None | 0 0
  1. local mon = peripheral.wrap("back")
  2. local total = 0
  3. monX, monY = mon.getSize()
  4.  
  5. --Fonction
  6.  
  7. function clear()
  8.   mon.setBackgroundColor(colors.black)
  9.   mon.clear()
  10.   mon.setCursorPos(1,1)
  11. end
  12.  
  13. function drawText(x, y, text, color_txt, color_bg)
  14.   mon.setBackgroundColor(color_bg)
  15.   mon.setTextColor(color_txt)
  16.   mon.setCursorPos(x,y)
  17.   mon.write(text)
  18. end
  19.  
  20. function drawLine(x, y, length, size, color_bar)
  21.   for yPos = y, y+size-1 do
  22.     mon.setBackgroundColor(color_bar)
  23.     mon.setCursorPos(x, yPos)
  24.     mon.write(string.rep(" ", length))
  25.   end
  26. end
  27.  
  28. function drawProg(x, y, name, length, size, minVal, maxVal, color_bar, color_bg)
  29.   drawLine(x, y, length, size, color_bg)
  30.   local barSize = math.floor((minVal/maxVal)*length)
  31.   drawLine(x, y, barSize, size, color_bar)
  32.   local text = name.." "..math.floor((minVal/maxVal)*100).."%"
  33.   if barSize > length/2+#text/2 then
  34.     drawText(x+length/2-#text/2, y+size/2, text, colors.black, color_bar)
  35.   elseif barSize > #text then
  36.     drawText((x+barSize)-#text, y+size/2, text, colors.black, color_bar)
  37.   else
  38.     drawText(x+length/2-#text/2, y+size/2, text, colors.black, color_bg)
  39.   end
  40. end
  41.  
  42. --End fonction
  43.  
  44. mon.setBackgroundColor(colors.black)
  45.  
  46. while true do
  47. mon.clear()
  48.  
  49. mon.setTextColor(colors.white)
  50. mon.setCursorPos(1,1)
  51. mon.setTextScale(1)
  52. mon.write("Monitor ..")
  53. sleep(1)
  54.  
  55. local mon = peripheral.wrap("back")
  56. if mon then
  57. mon.setTextColor(colors.green)
  58. mon.write(" Ok")
  59.  
  60. else
  61. mon.setTextColor(colors.red)
  62. mon.write(" Failed")
  63. stop()
  64. end
  65.  
  66. sleep(1)
  67. mon.setTextColor(colors.white)
  68. mon.setCursorPos(1,2)
  69. mon.setTextScale(1)
  70. mon.write("Modem ..")
  71. sleep(1)
  72.  
  73. local modem = peripheral.wrap("top")
  74. if modem then
  75. mon.setTextColor(colors.green)
  76. mon.write(" Ok")
  77. else
  78. mon.setTextColor(colors.red)
  79. mon.write(" Failed")
  80. stop()
  81. end
  82.  
  83. sleep(1)
  84.  
  85. mon.setTextColor(colors.white)
  86. mon.setCursorPos(1,4)
  87. mon.write("Waiting for a signal ..")
  88.  
  89. while modem do
  90. modem.open(7)
  91. local event, modemSide, senderChannel, replyChannel, mfsu, senderDistance = os.pullEvent("modem_message")
  92. total = mfsu / 4000000 * 100
  93.  
  94. clear()
  95. drawProg(0,0, "MFE", 40, 6, total, 100, colors.green, colors.gray)
  96.  
  97. mon.setBackgroundColor(colors.black)
  98. mon.setCursorPos(1,6)
  99. mon.setTextColor(colors.white)
  100.  
  101. sleep(0.2)
  102.  
  103.  
  104. end
  105. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement