Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. function pixelCalc (percent, usableHe, maxHe) --kiszámolja a megadott százalékot pixelbe
  2. pixel = math.abs(math.floor(usabelHe * percent / 100) - usableHe)
  3. pixel = pixel + maxHe
  4. debugWrite("pixelCalc:"..pixel)
  5. return pixel
  6.  
  7.  
  8. end
  9.  
  10. function drawGraph (pixelArray, monitor, maxW, minW) -- rajzol egy grafikont a pixel tömb alapján
  11. monitor.clear()
  12. monitor2= boot("monitor_2")
  13. for i=1, #pixelArray do
  14. if maxW-i < minW then
  15. paintutils.drawPixel(maxW-i, pixelArray[i], colours.blue)
  16. debugWrite("drawGraph: W= ".. maxW-i .. "H= " pixelArray[i])
  17. return
  18. else
  19.  
  20. debugWrite("drawGrap: end of draw")
  21. return
  22. end
  23. end
  24. return
  25.  
  26. end
  27.  
  28. function updatePixelArray(oldArray, newPercent) --létrehozza a pixel tömböt
  29.  
  30. newArray = {}
  31. newArray[1] = newPercent
  32. debugWrite("updatePixel")
  33. for i = 1, #oldArray - 1 do
  34. newArray[i+1] = oldArray[i]
  35. end
  36. return newArray
  37. end
  38.  
  39. function usabelHe (minHe, maxHe)
  40. return maxHe-minHe
  41.  
  42. end
  43.  
  44. function createBlankArray(maxWi,minWi)
  45.  
  46. usableWi = maxWi - minWi
  47. blankArray = {}
  48. for i = 1, usableWi do
  49. blankArray[i] = 0
  50. end
  51. return blankArray
  52. end
  53.  
  54. function boot (side)
  55. if peripheral.isPresent(side) == true then
  56. return peripheral.wrap(side)
  57. else
  58. os.exit()
  59. end
  60. end
  61.  
  62. function toltSzaz (re)
  63. stor = re.getEnergyStored()
  64. storMax = re.getMaxEnergyStored()
  65.  
  66. return stor / storMax * 100
  67. end
  68.  
  69.  
  70. function setOffSend (re)
  71. re.setEnergySend(0)
  72. end
  73.  
  74. function setOnSend (re)
  75. re.setEnergySend(100)
  76. end
  77.  
  78. function checkArray (perArray)
  79. toltArray = {}
  80. for i=1, #perArray do
  81. toltArray[i] = toltSzaz(perArray[i])
  82. end
  83. return toltArray
  84. end
  85.  
  86. function debugWrite (input)
  87. debugMonitor = boot("monitor_1")
  88. local _,CY= debugMonitor.getCursorPos()
  89. debugMonitor.setCursorPos(1,CY+1)
  90. debugMonitor.write(input)
  91. return
  92.  
  93.  
  94. end
  95.  
  96.  
  97.  
  98. perID ={"redstone_energy_cell_0","redstone_energy_cell_1","redstone_energy_cell_2","redstone_energy_cell_3","redstone_energy_cell_4"}
  99. perWrapped = {}
  100. monitor = boot("monitor_0")
  101. monitorDebug = boot("monitor_1")
  102.  
  103.  
  104. term.redirect(monitor)
  105.  
  106. dataArray = {}
  107.  
  108. local monitorW, monitorH = monitor.getSize()
  109. dataArray = createBlankArray(monitorW, 1);
  110.  
  111. while true do
  112.  
  113. for i = 1, #perID do
  114. perWrapped[i] = boot(perID[i])
  115. end
  116.  
  117. toltott = checkArray(perWrapped)
  118.  
  119. ossz = 0
  120.  
  121. for i = 1, #toltott do
  122. ossz = ossz + toltott[i]
  123.  
  124. end
  125.  
  126. ossz = ossz / 5
  127.  
  128. rsSide = "top"
  129. if ossz > 90 then
  130. redstone.setOutput(rsSide, false)
  131. sleep(10)
  132. else
  133. redstone.setOutput(rsSide, true)
  134. end
  135. dataArray = updatePixelArray(dataArray, monitorH)
  136. drawGraph(dataArray, monitor, monitorW, 1)
  137. sleep(1)
  138. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement