Advertisement
quenti77

screen_graph

Apr 21st, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.15 KB | None | 0 0
  1. -- Init program
  2. rednetSide = "top"
  3. m = peripheral.wrap("back")
  4. idSensorPC = 19
  5.  
  6. mfsuList = {}
  7.  
  8. mfsuOffset = 0
  9. td = true
  10. tick = 0
  11. titre = "MFSU VISUALIZER"
  12.  
  13. lavaButton = false
  14.  
  15. function horizontalLine(i, j)
  16.     m.setCursorPos(i, j)
  17.     if i > 1 and i < 36 then
  18.         m.write("-")
  19.     else
  20.         m.write("+")
  21.     end
  22. end
  23.  
  24. function drawCadre()
  25.     m.setBackgroundColor(colors.black)
  26.     m.setTextColor(colors.white)
  27.     m.clear()
  28.    
  29.     for i = 2, 35 do
  30.         m.setCursorPos(1, i)
  31.         m.write("|")
  32.         m.setCursorPos(36, i)
  33.         m.write("|")
  34.     end
  35.    
  36.     for i = 1, 36 do
  37.         horizontalLine(i,  1)
  38.         horizontalLine(i,  3)
  39.         horizontalLine(i, 16)
  40.         horizontalLine(i, 20)
  41.     end
  42. end
  43.  
  44. function drawInterface()
  45.     milieu = (36 / 2) - (string.len(titre) / 2) + 1
  46.     m.setCursorPos(milieu, 2)
  47.     m.setTextColor(colors.yellow)
  48.     m.write(titre)
  49.     m.setTextColor(colors.white)
  50. end
  51.  
  52. function drawEnergy()
  53.     if mfsuList ~= nil and type(mfsuList) == "table" then
  54.         if mfsuOffset < (#mfsuList) and #mfsuList > 0 then
  55.             for i = mfsuOffset, (mfsuOffset + 1) do
  56.                 lenght = (mfsuList[i]["p"] / 100) * 28
  57.                
  58.                 cl = colors.red
  59.                 if lenght < 4 then
  60.                     cl = colors.red
  61.                 elseif lenght < 21 then
  62.                     cl = colors.orange
  63.                 elseif lenght > 20 then
  64.                     cl = colors.lime
  65.                 end
  66.                
  67.                 y = (i - mfsuOffset) * 5
  68.    
  69.                 percent = ""..mfsuList[i]["p"].."%"
  70.     numId = i + 1
  71.     num = " "..numId
  72.                
  73.                 drawBar(2, lenght + 2, y + 5, y + 8, num, percent, cl)
  74.             end
  75.         end
  76.     end
  77. end
  78.  
  79. function drawBar(offset, limite, ymin, ymax, n, msg, couleur)
  80.     for i = ymin, ymax do
  81.         for j = offset, limite do
  82.             m.setCursorPos(j, i)
  83.             m.setBackgroundColor(couleur)
  84.             m.write(" ")
  85.         end
  86.     end
  87.     m.setBackgroundColor(colors.black)
  88.  m.setCursorPos(36 - string.len(n) - 1, ymin)
  89.  m.write(n)
  90.     m.setCursorPos(36 - string.len(msg) - 1, ymin + 1)
  91.     m.write(msg)
  92. end
  93.  
  94. rednet.open(rednetSide)
  95. while true do
  96.     event, id, msg, d = os.pullEvent()
  97.  
  98.  if tick >= 3 then
  99.   tick = 0
  100.   if td then
  101.    if (mfsuOffset + 1) == #mfsuList then
  102.     td = false
  103.    else
  104.     mfsuOffset = mfsuOffset + 1
  105.    end
  106.   else
  107.    if mfsuOffset == 0 then
  108.     td = true
  109.     else
  110.      mfsuOffset = mfsuOffset - 1
  111.    end
  112.   end
  113.  else
  114.   tick = tick + 1
  115.  end
  116.  
  117.     if event == "monitor_touch" then
  118.         print(msg)
  119.         print(d)
  120.  
  121.   message = {}
  122.  
  123.   if msg > 1 and msg < 8 and d > 16 and d < 20 then
  124.    if lavaButton then
  125.     lavaButton = false
  126.     message["button"] = "off_lava"
  127.    else
  128.     lavaButton = true
  129.     message["button"] = "on_lava"
  130.    end
  131.   end
  132.  
  133.   r = ""
  134.    
  135.   while r ~= "ok" do
  136.    rednet.send(idSensorPC, textutils.serialize(message))
  137.    id, r, d = rednet.receive(0.5)
  138.   end
  139.  end
  140.  
  141.     if event == "rednet_message" then
  142.         if id ~= nil and id == idSensorPC then
  143.             if msg ~= nil then
  144.                 mfsuList = textutils.unserialize(msg)
  145.             end
  146.         end
  147.     end
  148.    
  149.     m.setTextScale(2)
  150.     drawCadre()
  151.     drawInterface()
  152.     drawEnergy()
  153.  
  154.  if lavaButton then
  155.   m.setBackgroundColor(colors.lime)
  156.  else
  157.   m.setBackgroundColor(colors.red)
  158.  end
  159.  m.setTextColor(colors.white)
  160.  
  161.  for i = 2, 7 do
  162.    for j = 17, 19 do
  163.      m.setCursorPos(i, j)
  164.      m.write(" ")
  165.    end
  166.  end
  167.  m.setCursorPos(2, 18)
  168.  m.write(" LAVE ")
  169.    
  170. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement