theo33500

EP6_ay_elec_interface

Oct 2nd, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.45 KB | None | 0 0
  1. --Plus d'info ici : https://www.youtube.com/watch?v=I5ypmkKHklQ
  2. --Code original par aypierre (https://www.youtube.com/user/aypierre)
  3. --Code réuploader sur Pastebin par theo33500 (https://twitter.com/theo33500)
  4.  
  5.  
  6. local p = {}
  7. m = peripheral.wrap("left")
  8. m.setTextScale(1)
  9. rednet.open("right")
  10. maxe = 4
  11. recentre = 4
  12.  
  13. function getData()
  14.     event, senderId, message, _ = os.pullEvent()
  15.     if senderId == 154 and event == "rednet_message" then
  16.         p = textutils.unserialize(message)
  17.     end
  18. end
  19.  
  20. function tabLn(input)
  21.     local int=0
  22.     for k,v in pairs(input) do
  23.         int=int+1
  24.     end
  25.     return int
  26. end
  27.  
  28. function comble(fin)
  29.     for i=1,fin do
  30.         m.write(" ")
  31.     end
  32.     m.setBackgroundColor(colors.black)
  33.     m.write(" ")
  34. end
  35.  
  36. function graphPrincipal()
  37.     m.setTextScale(1)
  38.     m.setBackgroundColor(colors.black)
  39.     m.clear()
  40.     x, _ = m.getSize()
  41.     j = math.ceil(x/(maxe+2))
  42.     m.setCursorPos(j+recentre,2)
  43.     s=0
  44.     t=2
  45.     for k,v in pairs(p) do
  46.         if k ~= "No label" and k ~= "ville" then
  47.             if s == maxe then  
  48.                 t = t+3
  49.                 m.setCursorPos(j+recentre,t)
  50.                 s = 0
  51.             end
  52.             s = s+1
  53.            
  54.             m.setBackgroundColor(colors.white)
  55.             if v==-1 then
  56.                 m.setTextColor(colors.red)
  57.             else
  58.                 m.setTextColor(colors.lightBlue)
  59.             end
  60.             m.write(" "..k.." ")
  61.             comble(j-#k-4)
  62.         end
  63.     end
  64.    
  65.     s=0
  66.     t=2
  67.     total = 0
  68.     m.setCursorPos(j+recentre,3)
  69.     for k,v in pairs(p) do
  70.         if k ~= "No label" and k ~= "ville" then
  71.             if s == maxe then  
  72.                 t = t+3
  73.                 m.setCursorPos(j+4,t+1)
  74.                 s = 0
  75.             end
  76.             s = s+1
  77.             if v==-1 then
  78.                 m.setBackgroundColor(colors.gray)
  79.                 m.setTextColor(colors.red)
  80.                 m.write(" DECO ")
  81.                 comble(j-8)
  82.             else
  83.                 if v>0 then
  84.                     m.setBackgroundColor(colors.lime)
  85.                     m.setTextColor(colors.black)
  86.                 else
  87.                     m.setBackgroundColor(colors.gray)
  88.                     m.setTextColor(colors.lightGray)           
  89.                 end
  90.                 vt=tostring(v/20)
  91.                 m.write(" "..vt.." ")
  92.                 comble(j-#vt-4)
  93.             end
  94.         else
  95.             if k == "ville" then
  96.                 total = v/20
  97.             end
  98.         end
  99.     end
  100.    
  101.     --m.setTextScale(4)
  102.     --x, _= m.getSize()
  103.    
  104.    
  105.     if total>0 then
  106.         m.setBackgroundColor(colors.lime)
  107.         m.setTextColor(colors.black)
  108.     else
  109.         m.setBackgroundColor(colors.gray)
  110.         m.setTextColor(colors.lightGray)   
  111.     end
  112.     t2 = tostring(total)
  113.     m.setCursorPos((x-#t2)/2-1,t+5)
  114.     for i=1,#t2+4 do m.write(" ") end
  115.     m.setCursorPos((x-#t2)/2-1,t+6)
  116.     m.write("  "..t2.."  ")
  117.     m.setCursorPos((x-#t2)/2-1,t+7)
  118.     for i=1,#t2+4 do m.write(" ") end
  119. end
  120.  
  121.  
  122. while true do
  123.     getData()
  124.     graphPrincipal()
  125. end
Advertisement
Add Comment
Please, Sign In to add comment