Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ===============================
- -- Setup monitor
- -- ===============================
- local mon = peripheral.wrap("top")
- local term_local = term.current() -- terminale standard del computer
- term.redirect(mon)
- -- Funzione per ridimensionare monitor in base all'immagine
- local function resizeMonitorForImage(img)
- local width = #img[1]
- local height = #img
- term_local.write("Larghezza: ", width,"Altezza: ",height)
- local possibleScales = {2, 1.5, 1, 0.75, 0.5}
- local scale = 0.5 -- default minimo
- for _, s in ipairs(possibleScales) do
- local w = math.floor(width * s)
- local h = math.floor(height * s)
- -- monitor.getSize() restituisce numero di caratteri disponibili
- local mWidth, mHeight = mon.getSize()
- if w <= mWidth and h <= mHeight then
- scale = s
- break
- end
- end
- term_local.write("Scala: ", scale)
- mon.setTextScale(scale)
- end
- -- ===============================
- -- Controllo e download immagine home se non esiste
- -- ===============================
- if not fs.exists("/home.nfp") then
- term_local.write("Carico img Home da pastebin")
- shell.run("pastebin get Kr7Q3eJC home.nfp")
- end
- local homeImg = paintutils.loadImage("/home.nfp")
- local function showHome()
- mon.clear()
- if homeImg then
- term_local.write("Faccio resize di img home")
- resizeMonitorForImage(homeImg)
- paintutils.drawImage(homeImg, 1, 1)
- else
- mon.setTextScale(0.5)
- mon.setCursorPos(1, 1)
- print("INSERIRE UN DISCO")
- end
- end
- -- ===============================
- -- Lato Disk Drive
- -- ===============================
- local driveSide = "left"
- -- ===============================
- -- Loop principale
- -- ===============================
- while true do
- if not disk.isPresent(driveSide) or not disk.hasData(driveSide) then
- term_local.write("Nessun Disco")
- showHome()
- sleep(1)
- else
- term_local.write("Disco Trovato")
- local framePath = "/disk/frame"
- if fs.exists(framePath) then
- local files = fs.list(framePath)
- local frames = {}
- for _, file in ipairs(files) do
- local fullPath = framePath .. "/" .. file
- if not fs.isDir(fullPath) then
- local ok, img = pcall(paintutils.loadImage, fullPath)
- if ok and img then
- table.insert(frames, img)
- end
- end
- end
- if #frames > 0 then
- while disk.isPresent(driveSide) and disk.hasData(driveSide) do
- for _, frame in ipairs(frames) do
- mon.clear()
- term_local.write("Faccio il resize del frame")
- resizeMonitorForImage(frame)
- paintutils.drawImage(frame, 1, 1)
- sleep(0.2)
- if not disk.isPresent(driveSide) or not disk.hasData(driveSide) then
- break
- end
- end
- end
- else
- mon.clear()
- mon.setTextScale(0.5)
- mon.setCursorPos(1, 1)
- print("NESSUNA IMMAGINE TROVATA SU /disk/frame")
- sleep(2)
- end
- else
- mon.clear()
- mon.setTextScale(0.5)
- mon.setCursorPos(1, 1)
- print("NESSUNA CARTELLA /disk/frame SUL DISCO")
- sleep(2)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment