Advertisement
Freack100

My Submission

Jul 28th, 2013
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.10 KB | None | 0 0
  1. --This is a little screensaver.
  2. --Made by H4X0RZ (I guess some people on the forums reqeusted this...)
  3. --To leave it, enter the password and press enter (if no password is entered just press enter)
  4.  
  5. --checking if advanced computer
  6. if term.isColour and term.isColour() then
  7.  
  8. else
  9.   error("Please use an advanced computer",0)
  10. end
  11.  
  12. --Varialbes
  13. local input = ""
  14. local password = ... or ""
  15. local oldPull = os.pullEvent
  16. os.pullEvent = os.pullEventRaw
  17. local running = true
  18. local BGc = colors.lightGray --Background color
  19. local Lc = colors.green --Line color
  20. local l = {} --lines
  21. local screenWidth,screenHeight = term.getSize()
  22. local speed = .4
  23.  
  24. --Initialization
  25. for i = 1, screenWidth do
  26.   if i % 2 == 1 then
  27.     l[i] = screenHeight
  28.   end
  29. end
  30.  
  31. --functions
  32. local function reading()
  33.   while running do
  34.     local enter = false
  35.     while not enter do
  36.       local sEvent, p1 = os.pullEvent()
  37.       if sEvent == "key" then
  38.         if p1 == keys.enter then
  39.           enter = true
  40.         elseif p1 == keys.backspace then
  41.           input = input:sub(1, #input - 1)
  42.         end
  43.       elseif sEvent == "char" then
  44.         input = input .. p1
  45.       end
  46.     end
  47.     if input == password then
  48.       running = false
  49.     end
  50.     input = ""
  51.   end
  52. end
  53.  
  54. local function update()
  55.   while running do
  56.     for k,v in pairs(l) do
  57.       if math.random(1,2) == 1 then
  58.         if l[k] > 1 then
  59.           l[k] = l[k] - 1
  60.         end
  61.       else
  62.         if l[k] < screenHeight then
  63.           l[k] = l[k] + 1
  64.         end
  65.       end
  66.     end
  67.   sleep(speed)
  68.   end
  69. end
  70.        
  71.  
  72. local function display()
  73.   while running do
  74.     term.setBackgroundColor(BGc)
  75.     term.clear()
  76.     term.setBackgroundColor(Lc)
  77.     for k,v in pairs(l) do
  78.       paintutils.drawLine(k,screenHeight,k,v,Lc)
  79.     end
  80.   sleep(speed)
  81.   end
  82. end
  83.  
  84. --main loop
  85. parallel.waitForAny(reading, update, display)
  86.  
  87. --The end
  88. os.pullEvent = oldPull
  89. term.setBackgroundColor(colors.black)
  90. term.clear()
  91. term.setCursorPos(1,1)
  92. term.setTextColor(colors.yellow)
  93. term.write(os.version())
  94. term.setTextColor(colors.white)
  95. term.setCursorPos(1,3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement