FoxWorn3365

Tabellone

Feb 14th, 2026 (edited)
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.68 KB | None | 0 0
  1. -- RGR - Tabellone partenze (e in futuro arrivi) treni alla stazione
  2. -- (C) 2026 interSex S.p.A.
  3.  
  4. -- Variabili da popolare
  5. screen_side = "back"
  6. station_name = "Karabash"
  7. station_code = "S0068"
  8.  
  9. -- Recupero periferiche
  10. screen = peripheral.wrap(screen_side)
  11.  
  12. -- Verifichiamo le specifiche
  13. width, height  = screen.getSize()
  14.  
  15. if width < 100 then
  16.     print("DIMENSIONI TROPPO PICCOLE!")
  17.     exit()
  18. end
  19.  
  20. if height < 20 then
  21.     print("DIMENSIONI TROPPO PICCOLE! (y)")
  22.     exit()
  23. end
  24.  
  25. -- Definizione funzioni (copiate da lego11 obv)
  26. function clear()
  27.     screen.clear()
  28.     screen.setCursorPos(1, 1)
  29. end
  30.  
  31. function clearRed()
  32.     sfondo(colors.red)
  33.     screen.clear()
  34.     screen.setCursorPos(1, 1)
  35. end
  36.  
  37. function colore(sfumatura)
  38.     screen.setTextColour(sfumatura)
  39. end
  40.  
  41. function sfondo(sfumaturaSfondo)
  42.     screen.setBackgroundColour(sfumaturaSfondo)
  43. end
  44.  
  45. function fineColore()
  46.     screen.setTextColour(colours.white)
  47. end
  48.  
  49. function fineSfondo()
  50.     screen.setBackgroundColour(colours.black)
  51. end
  52.  
  53. -- IMPLEMENTAZIONE DEL DRAWFILLEDBOX
  54. local function drawPixelInternal(xPos, yPos)
  55.     screen.setCursorPos(xPos, yPos)
  56.     screen.write(" ")
  57. end
  58.  
  59. local tColourLookup = {}
  60. for n = 1, 16 do
  61.     tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
  62. end
  63.  
  64. function drawFilledBox(startX, startY, endX, endY, nColour)
  65.     if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~= "number" or type(endY) ~= "number" or
  66.         (nColour ~= nil and type(nColour) ~= "number") then
  67.         error("Expected startX, startY, endX, endY, colour", 2)
  68.     end
  69.  
  70.     startX = math.floor(startX)
  71.     startY = math.floor(startY)
  72.     endX = math.floor(endX)
  73.     endY = math.floor(endY)
  74.  
  75.     if nColour then
  76.         screen.setBackgroundColor(nColour)
  77.     end
  78.     if startX == endX and startY == endY then
  79.         drawPixelInternal(startX, startY)
  80.         return
  81.     end
  82.  
  83.     local minX = math.min(startX, endX)
  84.     if minX == startX then
  85.         minY = startY
  86.         maxX = endX
  87.         maxY = endY
  88.     else
  89.         minY = endY
  90.         maxX = startX
  91.         maxY = startY
  92.     end
  93.  
  94.     for x = minX, maxX do
  95.         for y = minY, maxY do
  96.             drawPixelInternal(x, y)
  97.         end
  98.     end
  99. end
  100.  
  101. function titolo(testo)
  102.     drawFilledBox(1, 1, width, 1, colors.yellow)
  103.     screen.setCursorPos((width - #testo) / 2, 1)
  104.     colore(colors.black)
  105.     screen.write(testo)
  106.     sfondo(colors.lightBlue)
  107. end
  108.  
  109. while true do
  110.     -- Richiediamo i dati
  111.     local data = textutils.unserialize(http.get("http://172.16.23.169:6009/api/cc/tabellone.php?station="..station_code))
  112.  
  113.     titolo(station_name.." - Partenze")
  114.  
  115.     screen.print(data)
  116.  
  117.     sleep(5)
  118. end
  119.  
Advertisement
Add Comment
Please, Sign In to add comment