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

Screensaver v1.1!

Started by Dlcruz129, 17 December 2012 - 05:19 AM
Dlcruz129 #1
Posted 17 December 2012 - 06:19 AM
Thanks to TheOriginalBIT for helping me fix some of my bugs. This is just a simple screensaver that draws random pixels, then clears the screen. You can go ahead and put this in your operating system without my permission.

Code: pastebin get XXW0r5zt

Changelog:
Spoilerv1.1
- Added Mouse Support
v1.0
- Initial Release
AndreWalia #2
Posted 17 December 2012 - 10:57 AM
I like it. But with most screen savers for IRL computers it also stops the screen saver if you click the mouse. So I added that by changing one line.

local maxX, maxY = term.getSize()
local count = 1
local d = {}
local resetTimer = os.startTimer(5)
local addTimer = os.startTimer(0.1)
local function clear()
  term.setBackgroundColor(colors.black)
  term.clear()
  term.setCursorPos(1,1)
end
while true do
  event = { os.pullEventRaw() }
  if event[1] == "key" or event[1] == "mouse_click" then
    clear()
    return
  elseif event[1] == "timer" then
    if event[2] == addTimer then
	  t = {
	  ["x"] = math.random(1,maxX),
	  ["y"] = math.random(1,maxY),
	  ["color"] = 2^math.random(0,15)
	  }
	  table.insert(d, t)
	  addTimer = os.startTimer(0.1)
    elseif event[2] == resetTimer then
	  d = {}
	  resetTimer = os.startTimer(5)
    end
  end
  clear()
  for _, v in pairs( d ) do
    term.setCursorPos( v["x"], v["y"] )
    term.setBackgroundColor(v["color"])
    write(" ")
  end
end
Its Pastebin id is fEAC4Ave
Dlcruz129 #3
Posted 17 December 2012 - 11:13 AM
I like it. But with most screen savers for IRL computers it also stops the screen saver if you click the mouse. So I added that by changing one line.

local maxX, maxY = term.getSize()
local count = 1
local d = {}
local resetTimer = os.startTimer(5)
local addTimer = os.startTimer(0.1)
local function clear()
  term.setBackgroundColor(colors.black)
  term.clear()
  term.setCursorPos(1,1)
end
while true do
  event = { os.pullEventRaw() }
  if event[1] == "key" or event[1] == "mouse_click" then
    clear()
    return
  elseif event[1] == "timer" then
    if event[2] == addTimer then
	  t = {
	  ["x"] = math.random(1,maxX),
	  ["y"] = math.random(1,maxY),
	  ["color"] = 2^math.random(0,15)
	  }
	  table.insert(d, t)
	  addTimer = os.startTimer(0.1)
    elseif event[2] == resetTimer then
	  d = {}
	  resetTimer = os.startTimer(5)
    end
  end
  clear()
  for _, v in pairs( d ) do
    term.setCursorPos( v["x"], v["y"] )
    term.setBackgroundColor(v["color"])
    write(" ")
  end
end
Its Pastebin id is fEAC4Ave

Ah, yes, completely forgot about the mouse. I'll add that later.
theoriginalbit #4
Posted 17 December 2012 - 03:21 PM
Thanks to TheOriginalBIT for helping me fix some of my bugs.

Your welcome :)/> I had similar issues with mine when I did it. You inspired me to release mine :)/>

I like it. But with most screen savers for IRL computers it also stops the screen saver if you click the mouse. So I added that by changing one line.

Would you not have it on any mouse event? o.O Thats what I did
Dlcruz129 #5
Posted 18 December 2012 - 07:47 AM
Version 1.1 is out!

New in this version: Clicking will now exit the screensaver.