This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
zedekblue's profile picture

Screensaver Help?

Started by zedekblue, 08 February 2013 - 06:53 PM
zedekblue #1
Posted 08 February 2013 - 07:53 PM
Hello!
I'm needing to create/wondering if it's possible to create–essentially what would be a image slideshow. A screensaver of sorts perhaps? I'm very new to Lua, only having successfully created a clock that actually updates itself to show the current time. (Amazing, right?)
This might be really stupid to ask considering how little I know about computercraft capabilities. But I want it to reference two different folders (Whether it be with the server files or somewhere online), whereas one folder's contents will display while a redstone signal is detected, and the other when it isn't. I want the images to act like an automatic slideshow, giving each image like ten or so seconds on the screen before moving on to the next.
I've been researching around trying to figure out how to do this, but I figured asking here for help would benefit me most. Thanks!
Lyqyd #2
Posted 09 February 2013 - 04:50 AM
Split into new topic.
AnDwHaT5 #3
Posted 09 February 2013 - 08:17 AM
hmm possible you can use one where it waits for a command and if no command found go into screen saver whick will be images (created by text art) going on the screen useing a simaler codeing to
file name: screensaver
________________________

print(" – _")
print(" / \ | |")
print(" | | | |")
print(" | \____ | |")
print(" | _ \ | |")
print(" | / \ | \_/")
sleep(5)
function.clear()
textutils.slowPrint("………………………………………….")
textutils.slowPrint("………………………………………….")
textutils.slowPrint("………………………………………….")
textutils.slowPrint("………………………………………….")
sleep(10)
shell.run("screensaver)





something like that would be a good screen saver but also think about the if input = false then
or something like that im not entirly sure… :P/>

~AnDwHaT5 @inc creator

… my coding didn't save right ….. my bad :P/>



~AnDwHaT5 @inc creator
Moody #4
Posted 09 February 2013 - 06:28 PM
If you dont want to create a file with code and want to simply draw a picture in ASCII art you can also just make a file with ASCII art and load it like so:

-- Parameters
local folder1path = "/screensaver1"
local folder2path = "/screensaver2"
local t = 1
local terminalWith,terminalHeigh = term.getSize()

-- Data processing
if not (fs.isDir(folder1path) and fs.isDir(folder2path)) then
return false
end
local ptable = {}
ptable[1] = fs.list(folder1path)
ptable[1].path = folder1path
ptable[2] = fs.list(folder2path)
ptable[2].path = folder2path
local cp = {}
cp[1],cp[2] = 1,1
local cf = 1

-- Loop through
while true do

if redstone.getInput("back",true) then
  cf = 2
else
  cf = 1
end
local cpath =  ptable[cf].path.."/"..ptable[cf][cp[cf]]

if not fs.exists(cpath) then
  print("file not found")
  return false
else
  local h = fs.open(cpath,"r")
  local ltable = {}
  for i = 1,terminalHeigh do
   local tmp = h.readLine()
   if tmp == nil then
	h.close()
	print("File incomplete")
	return false
   else
	ltable[i] = tmp
   end
  end
  h.close()

  term.clear()
  term.setCursorPos(1,1)

  for i = 1,#ltable do
   print(ltable[i])
  end

  os.startTimer(t)
  while true do
   local event = os.pullEvent()
   if event == "key" then
	print("key pressed")
	return true
   elseif event == "timer" then
	cp[cf] = 1+ (cp[cf]%(#(ptable[cf])))
	break
   elseif event == "redstone" then
	break
   end
  end
end
end

This basically creates what you want:
a Screensaver that switches between pictures it gets as ascii-art from external files and different folders.
Although im not certain if you want to break the program on pressing a key - but if you dont, just remove the check for " event == "key" "

you could also adapt it let the pictures scroll in from the side or be blanked out and all that funny stuff
You could also process a config file where you store all folderpaths and the according redstone-inputside; the basic concept should be clear from my code.

if you want to run it simultanously with your shell, check this out
http://www.computerc...ce-without-gui/
or if you want to dive in further:
http://www.computerc...irect-ctrlkeys/
getting it to work with basic coroutines would be very tricky, i guess

to let it check if a keypress is done you can do before your actual code:

local action = true
local btime = 2
while true do
os.startTimer(btime)
while true do
  local event = os.pullEvent()
  if event == "timer" then
   break
  elseif event == "key" then
   action = true
  end
end
if not action then
  break
else
  action = false
end
end


if you got any questions about the code or else, just ask away, i know its messy, but i was feeling lazy :P/>

so long
theoriginalbit #5
Posted 09 February 2013 - 07:06 PM
It is very possible to do it. Click on the link in my signature and feel free to take a look at my screensaver API for any inspiration plus what was stated in the above reply. And if you have any questions about how anything works feel free to ask me in a PM :)/>