Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --#filename:matrix.lua
- --#version:1.0
- --#author:Zen
- --#Youtube: zenplayHD
- -- Matrix screensaver V1.0
- local mobj = {}
- do -- Standart variables.
- mobj.x = 0
- mobj.y = 0 -- Offscreen
- mobj.lingerMin = 3 -- Minimum time to linger (frames)
- mobj.lingerMax = 10 -- Maximum time to linger
- mobj.linger = 10 -- How long this object will linger
- mobj.tailLenMin = 3 -- Minimum tail length
- mobj.tailLenMax = 10 -- Maximum tail length
- mobj.tailLen = 10
- mobj.chars = "1234567890-=!@#$%^&*()_+qwertyuiop[]QWERTYUIOP{}asdfghjkl;'\\ASDFGHJKL:\"|zxcvbnm,./ZXCVBNM<>?"
- mobj.charsLen = mobj.chars:len()
- mobj.currentTail = {"a", "a", "a", "a", "a", "a", "a", "a", "a", "a"}
- mobj.secretText = {}
- mobj.skipFrame = 0
- mobj.skipFrameMin = 1
- mobj.skipFrameMax = 3
- mobj.skipFrameMod = -1
- mobj.currFrame = 0
- end
- function mobj:new(o, ...)
- local o = o or {}
- setmetatable(o, self)
- self.__index = self
- o:__init(...)
- return o
- end
- function mobj:__init(x)
- self.linger = math.random(self.lingerMin, self.lingerMax)
- self.tailLen = math.random(self.tailLenMin, self.tailLenMax)
- self.x = x
- self.y = 1
- self.nFrame = 1
- self.currentTail = {}
- self.skipFrame = math.random(self.skipFrameMin, self.skipFrameMax) + self.skipFrameMod
- end
- function mobj:randomLinger()
- self.linger = math.random(self.lingerMin, self.lingerMax)
- end
- function mobj:printPos(x, y, sText)
- term.setCursorPos(x, y)
- term.write(sText)
- end
- function mobj:printPosT(x, y, sText)
- if self.secretText[y] and self.secretText[y][x] then
- sText = self.secretText[y][x]
- end
- return self:printPos(x, y, sText)
- end
- function mobj:randomChar()
- local r = math.random(1, self.charsLen)
- return string.sub(self.chars, r, r)
- end
- function mobj:printTail()
- for i = 1, self.tailLen do
- if not self.currentTail[i] then break end
- self:printPosT(self.x, self.y - i, self.currentTail[i])
- end
- end
- local termX, termY = term.getSize()
- do
- for y = 1, termY do
- mobj.secretText[y] = {}
- end
- function mobj:addSecretText(x, y, sText)
- if sText:len() + x > termX then
- -- lolno.
- else
- for i = 1, sText:len() do
- local chr = sText:sub(i, i)
- self.secretText[y][x + i-1] = chr
- end
- end
- end
- function mobj:addSecretTextD(x, y, dir, sText)
- -- 1 = bottomright, 2 = bottomleft, 3 = topright, 4 = topleft
- local xmod = dir %2 == 1 and 1 or -1
- local ymod = (dir == 1 or dir == 2) and 1 or -1
- local finalx, finaly = x + (xmod * sText:len()), y + (ymod *sText:len())
- --print("finalx, finaly", finalx, finaly)
- --read()
- local cx, cy = x, y
- for i = 1, sText:len() do
- local cx, cy = x + (xmod * (i -1)), y + (ymod * (i -1))
- if self.secretText[cy] then
- self.secretText[cy][cx] = sText:sub(i, i)
- end
- end
- end
- end
- function mobj:render()
- self:printTail()
- local sSkip = false
- if self.currFrame ~= self.skipFrame then
- self.currFrame = self.currFrame + 1
- else
- self.currFrame = 0
- self.nFrame = self.nFrame + 1
- if self.nFrame == self.linger then
- table.insert(self.currentTail, 1, self.lastRandomChar)
- self:printPosT(self.x, self.y, self.currentTail[1])
- self.y = self.y + 1
- self.nFrame = 1
- if self.y > termY + self.tailLen then
- self:__init(self.x)
- end
- sSkip = true
- else
- self.lastRandomChar = self:randomChar()
- end
- end
- if not sSkip then
- self:printPos(self.x, self.y, self.lastRandomChar)
- end
- end
- local objects = {}
- local eventT
- function init()
- for i = 1, termX do
- objects[i] = mobj:new({}, i)
- end
- eventT = os.startTimer(0)
- end
- function render()
- term.clear()
- for _, k in pairs(objects) do
- k:render()
- end
- end
- mobj:addSecretTextD(15, 4, 1, "Zen")
- mobj:addSecretTextD(18, 4, 1, "made me")
- mobj:addSecretTextD(21, 4, 1, "do this.")
- mobj:addSecretText(15, 15, "Spacebar to exit.")
- init()
- while true do
- local e, p1, p2 = os.pullEvent()
- if e == "timer" and p1 == eventT then
- eventT = os.startTimer(0.05) -- 20 fps
- render()
- elseif e == "key" and p1 == 57 then
- term.clear()
- term.setCursorPos(1,1)
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement