pheonix46110

ay_elec_interface

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