Advertisement
Uranium_49

Untitled

Dec 16th, 2022 (edited)
858
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.63 KB | None | 0 0
  1. local mon = peripheral.wrap("top")
  2. local modem = peripheral.wrap("back")
  3.  
  4. modem.open(1)
  5.  
  6. mon.clear()
  7. mon.setBackgroundColor(colors.black)
  8. mon.clear()
  9.  
  10. sizeX, sizeY = mon.getSize()
  11.  
  12. function boxe(x,y,xa,ya,mon,titre)
  13.  
  14.     mon.setTextScale(1)
  15.     mon.setCursorPos(x,y)
  16.     mon.setBackgroundColor(colors.gray)
  17.     mon.write("  ")
  18.     mon.setBackgroundColor(colors.black)
  19.     mon.setTextColor(colors.yellow)
  20.     mon.setCursorPos(x+2,y)
  21.     mon.write(" "..titre.." ")
  22.  
  23.     local xc, yc = mon.getCursorPos()
  24.     for xc=xc,xa-1 do
  25.         mon.setCursorPos(xc,y)
  26.         mon.setBackgroundColor(colors.gray)
  27.         mon.write(" ")
  28.         xc = xc+1
  29.     end
  30.     local xc, yc = mon.getCursorPos()
  31.     yc = y+1
  32.     for yc=y,ya do
  33.         mon.setCursorPos(x,yc)
  34.         mon.setBackgroundColor(colors.gray)
  35.         mon.write(" ")
  36.         mon.setCursorPos(xa,yc)
  37.         mon.setBackgroundColor(colors.gray)
  38.         mon.write(" ")
  39.         yc = yc + 1
  40.     end
  41.     xb = x
  42.     for xb=x,xa do
  43.         mon.setCursorPos(xb,ya)
  44.         mon.setBackgroundColor(colors.gray)
  45.         mon.write(" ")
  46.         xb = xb + 1
  47.     end
  48. end
  49.  
  50. local Prod = {}
  51.  
  52. for i=1,3600 do
  53.     Prod[i] = 1
  54. end
  55.  
  56. local zoomTemp = 0
  57.  
  58. function graph(x,y,xa,ya,mon,name,dataTable,value,zoom)
  59.    
  60.     xb = xa-x
  61.     yb = ya-y
  62.    
  63.     --set datatable
  64.     for i=1,3600 do
  65.         dataTable[i] = dataTable[i+1]
  66.     end
  67.     dataTable[3600] = value
  68.     maxValue = 1
  69.     for i=2,3600 do
  70.         if maxValue < dataTable[i] then
  71.             maxValue = dataTable[i] + (dataTable[i]*0.1)
  72.         end
  73.     end
  74.    
  75.     --print graph
  76.     xc = xb-4
  77.     yc = yb-8
  78.     if zoomTemp == 0 then
  79.         zoomTemp = zoom
  80.  
  81.         for i=0, xc do
  82.             tempValue = dataTable[3600-i*zoom]
  83.             pointY = (yc*(maxValue-tempValue)/maxValue)
  84.  
  85.             if tempValue >1 then
  86.                 if pointY >= yc then
  87.                     pointY=yc
  88.                 end
  89.                 for yend=0, pointY do
  90.                     mon.setBackgroundColor(colors.gray)
  91.                     mon.setCursorPos((x+2+xc-i),y+2+yend)
  92.                     mon.write(" ")
  93.                 end
  94.                 for yend=pointY, (yc+0.999999) do
  95.                     mon.setBackgroundColor(colors.green)
  96.                     mon.setCursorPos((x+2+xc-i),y+2+yend)
  97.                     mon.write(" ")
  98.                 end
  99.             else
  100.                 yend = 0
  101.                 for yend=0, yc do
  102.                    mon.setBackgroundColor(colors.gray)
  103.                    mon.setCursorPos((x+2+xc-i),y+2+yend)
  104.                    mon.write(" ")
  105.                 end
  106.             end
  107.         end
  108.  
  109.         right(xa,y+1,maxValue.."rf/t",mon)
  110.         pointY= (yc*(maxValue-dataTable[3600])/maxValue)
  111.         right(xa,y+1+pointY,dataTable[3600].."rf/t",mon)
  112.     end
  113.  
  114.     for i=0, xa-x do
  115.         mon.setCursorPos(x+i,ya-4)
  116.         mon.setBackgroundColor(colors.gray)
  117.         mon.write(" ")
  118.     end
  119.    
  120.     boxe(x,y,xa,ya,mon,name)
  121.    
  122.     mon.setBackgroundColor(colors.black)
  123.     mon.setCursorPos(x+2,ya-2)
  124.     mon.write("Zoom : 1/"..zoom)
  125.    
  126.     zoomTemp = zoomTemp - 1
  127.    
  128. end
  129.  
  130. function right(rightX,rightY,value,mon)
  131.     mon.setBackgroundColor(colors.black)
  132.     mon.setTextColor(colors.black)
  133.     mon.setCursorPos(1,1)
  134.     mon.write(value)
  135.     rightTempX,rightTempY = mon.getCursorPos()
  136.     mon.setCursorPos(rightX-rightTempX,rightY)
  137.     mon.setBackgroundColor(colors.gray)
  138.     mon.setTextColor(colors.white)
  139.     mon.write(value)
  140. end
  141.  
  142. while true do
  143.  
  144.     event, side, frenquency, replayFrequency, message, distance = os.pullEvent("modem_message")
  145.    
  146.     batteryG1 = message.batteryG1
  147.     batteryG2 = message.batteryG2
  148.     batteryG3 = message.batteryG3
  149.     batteryG4 = message.batteryG4
  150.     batteryG5 = message.batteryG5
  151.     capacity = message.capacity*5
  152.     compteur1 = message.compteur1
  153.     compteur2 = message.compteur2
  154.     compteur3 = message.compteur3
  155.     transfer= compteur1+compteur2+compteur3
  156.     totalBattery = batteryG1+batteryG2+batteryG3+batteryG4+batteryG5
  157.  
  158.     message = {
  159.         status = null
  160.     }
  161.     if level <= 80 then
  162.         message = {
  163.             status  = true
  164.         }
  165.     end  
  166.     if level >= 95 then
  167.         message = {
  168.             status = false
  169.         }
  170.     end
  171.     modem.open(5)
  172.     print(textutils.serialise(message))
  173.     modem.transmit(5,10,message)
  174.     modem.close(5)
  175.  
  176.     graph(2,2,(((sizeX-1)*(2/5))-1),(sizeY-1),mon,"Production",Prod,transfer,2)
  177.     boxe(((sizeX-1)*(2/5)+1),2,((sizeX-1)*(4/5)-1),(sizeY-1),mon,"Controle room")
  178.     boxe(((sizeX-1)*(4/5)+1),2,(sizeX-1),(sizeY-1),mon,"Battery level")
  179.    
  180.     sleep(1)
  181.  
  182. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement