tommy2805

Tv con dischi

Oct 4th, 2025 (edited)
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.60 KB | None | 0 0
  1. -- ===============================
  2. -- Setup monitor
  3. -- ===============================
  4. local mon = peripheral.wrap("top")
  5. local term_local = term.current() -- terminale standard del computer
  6.  
  7. term.redirect(mon)
  8.  
  9. -- Funzione per ridimensionare monitor in base all'immagine
  10. local function resizeMonitorForImage(img)
  11.     local width = #img[1]
  12.     local height = #img
  13.  
  14.     term_local.write("Larghezza: ", width,"Altezza: ",height)
  15.  
  16.     local possibleScales = {2, 1.5, 1, 0.75, 0.5}
  17.     local scale = 0.5 -- default minimo
  18.  
  19.     for _, s in ipairs(possibleScales) do
  20.         local w = math.floor(width * s)
  21.         local h = math.floor(height * s)
  22.         -- monitor.getSize() restituisce numero di caratteri disponibili
  23.         local mWidth, mHeight = mon.getSize()
  24.         if w <= mWidth and h <= mHeight then
  25.             scale = s
  26.             break
  27.         end
  28.     end
  29.  
  30.     term_local.write("Scala: ", scale)
  31.     mon.setTextScale(scale)
  32. end
  33.  
  34. -- ===============================
  35. -- Controllo e download immagine home se non esiste
  36. -- ===============================
  37. if not fs.exists("/home.nfp") then
  38.     term_local.write("Carico img Home da pastebin")
  39.     shell.run("pastebin get Kr7Q3eJC home.nfp")
  40. end
  41.  
  42. local homeImg = paintutils.loadImage("/home.nfp")
  43.  
  44. local function showHome()
  45.     mon.clear()
  46.     if homeImg then
  47.         term_local.write("Faccio resize di img home")
  48.         resizeMonitorForImage(homeImg)
  49.         paintutils.drawImage(homeImg, 1, 1)
  50.     else
  51.         mon.setTextScale(0.5)
  52.         mon.setCursorPos(1, 1)
  53.         print("INSERIRE UN DISCO")
  54.     end
  55. end
  56.  
  57. -- ===============================
  58. -- Lato Disk Drive
  59. -- ===============================
  60. local driveSide = "left"
  61.  
  62. -- ===============================
  63. -- Loop principale
  64. -- ===============================
  65. while true do
  66.     if not disk.isPresent(driveSide) or not disk.hasData(driveSide) then
  67.         term_local.write("Nessun Disco")
  68.         showHome()
  69.         sleep(1)
  70.     else
  71.         term_local.write("Disco Trovato")
  72.         local framePath = "/disk/frame"
  73.         if fs.exists(framePath) then
  74.             local files = fs.list(framePath)
  75.             local frames = {}
  76.  
  77.             for _, file in ipairs(files) do
  78.                 local fullPath = framePath .. "/" .. file
  79.                 if not fs.isDir(fullPath) then
  80.                     local ok, img = pcall(paintutils.loadImage, fullPath)
  81.                     if ok and img then
  82.                         table.insert(frames, img)
  83.                     end
  84.                 end
  85.             end
  86.  
  87.             if #frames > 0 then
  88.                 while disk.isPresent(driveSide) and disk.hasData(driveSide) do
  89.                     for _, frame in ipairs(frames) do
  90.                         mon.clear()
  91.                         term_local.write("Faccio il resize del frame")
  92.                         resizeMonitorForImage(frame)
  93.                         paintutils.drawImage(frame, 1, 1)
  94.                         sleep(0.2)
  95.                         if not disk.isPresent(driveSide) or not disk.hasData(driveSide) then
  96.                             break
  97.                         end
  98.                     end
  99.                 end
  100.             else
  101.                 mon.clear()
  102.                 mon.setTextScale(0.5)
  103.                 mon.setCursorPos(1, 1)
  104.                 print("NESSUNA IMMAGINE TROVATA SU /disk/frame")
  105.                 sleep(2)
  106.             end
  107.         else
  108.             mon.clear()
  109.             mon.setTextScale(0.5)
  110.             mon.setCursorPos(1, 1)
  111.             print("NESSUNA CARTELLA /disk/frame SUL DISCO")
  112.             sleep(2)
  113.         end
  114.     end
  115. end
  116.  
Advertisement
Add Comment
Please, Sign In to add comment