Ulyssedu45

EP6_ay_elec_interface.lua

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