Advertisement
AdslHouba

Ecran de surveillance induction casing (CC)

Dec 18th, 2016
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.54 KB | None | 0 0
  1. -- Vidéo demo : https://www.youtube.com/watch?v=UvJogfi7gTc
  2. -- Vidéo explication : https://www.youtube.com/watch?v=55f6zG3821Y
  3. local liste={
  4.     {
  5.         p='Matrice d\'induction_13',
  6.         nom='Laser'
  7.     },{
  8.         p='Matrice d\'induction_3',
  9.         nom='QG'
  10.     },{
  11.         p='Matrice d\'induction_4',
  12.         nom='Pierre'
  13.     },{
  14.         p='Matrice d\'induction_1',
  15.         nom='Mekanism'
  16.     },{
  17.         p='Matrice d\'induction_2',
  18.         nom='AE2'
  19.     },{
  20.         p='Matrice d\'induction_12',
  21.         nom='Reacteur'
  22.     },{
  23.         p='Matrice d\'induction_0',
  24.         nom='Botania'
  25.     },{
  26.         p='Matrice d\'induction_8',
  27.         nom='Galacticraft'
  28.     }
  29. }
  30. local ppPrincipal=peripheral.wrap('Matrice d\'induction_14')
  31.  
  32. function formatChiff(c)
  33.     local mill=math.floor(c/1000)
  34.     if mill==0 then
  35.         return c
  36.     else
  37.         local unit=math.floor(c-(mill*1000))
  38.         if unit<10 then
  39.             return mill.." 00"..unit
  40.         elseif unit<100 then
  41.             return mill.." 0"..unit
  42.         else
  43.             return mill.." "..unit
  44.         end
  45.     end
  46. end
  47.  
  48.  
  49. local ecran=peripheral.find("monitor")
  50. ecran.setTextScale(2)
  51. ecran.clear()
  52. ecran.setCursorPos(5,2)
  53. ecran.write("Consommation")
  54.  
  55. local derPost=0
  56. for i, d in pairs(liste) do    
  57.     liste[i].pp=peripheral.wrap(liste[i].p)
  58.     print(liste[i].p)
  59.     print(liste[i].pp)
  60.    
  61.     liste[i].win1=window.create(ecran,1,i+3,21,1,true)
  62.     liste[i].win2=window.create(ecran,11,i+3,10,1,true)
  63.     if i%2==0 then
  64.         liste[i].win1.setBackgroundColor(colors.blue)
  65.         liste[i].win2.setBackgroundColor(colors.blue)
  66.     else
  67.         liste[i].win1.setBackgroundColor(colors.lightBlue)
  68.         liste[i].win2.setBackgroundColor(colors.lightBlue)
  69.     end
  70.     liste[i].win1.clear()
  71.     liste[i].win1.setCursorPos(2,1)
  72.     liste[i].win1.write(liste[i].nom)
  73.    
  74.     derPost=i
  75. end
  76.  
  77. ecran.setCursorPos(2,derPost+4)
  78. ecran.write("Total")
  79. local winTotal=window.create(ecran,11,derPost+4,10,1,true)
  80.  
  81. ecran.setCursorPos(6,derPost+6)
  82. ecran.write("Production")
  83. local winProduction=window.create(ecran,11,derPost+8,10,1,true)
  84.  
  85.  
  86. while true do
  87.     for i, d in pairs(liste) do        
  88.         chiffString=formatChiff(liste[i].pp.getOutput()*4)
  89.         chiffStringTaille=string.len(chiffString)
  90.         liste[i].win2.clear()  
  91.         liste[i].win2.setCursorPos(10-chiffStringTaille,1)
  92.         liste[i].win2.write(chiffString)
  93.     end
  94.    
  95.     totalString=formatChiff(ppPrincipal.getOutput())
  96.     totalStringTaille=string.len(totalString)
  97.     winTotal.clear()
  98.     winTotal.setCursorPos(10-totalStringTaille,1)
  99.     winTotal.write(totalString)
  100.    
  101.     totalString=formatChiff(ppPrincipal.getInput())
  102.     totalStringTaille=string.len(totalString)
  103.     winProduction.clear()
  104.     winProduction.setCursorPos(10-totalStringTaille,1)
  105.     winProduction.write(totalString)   
  106.    
  107.     os.sleep(5)
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement