SHOW:
|
|
- or go back to the newest paste.
| 1 | - | --#filename:matrix-ss |
| 1 | + | -- Matrix screensaver v0.7 |
| 2 | - | --#version:0.8 |
| 2 | + | |
| 3 | - | --#author:Advert |
| 3 | + | |
| 4 | - | -- Matrix screensaver v0.8 |
| 4 | + | |
| 5 | local mobj = {}
| |
| 6 | do -- Standart variables. | |
| 7 | mobj.x = 0 | |
| 8 | mobj.y = 0 -- Offscreen | |
| 9 | mobj.lingerMin = 3 -- Minimum time to linger (frames) | |
| 10 | mobj.lingerMax = 10 -- Maximum time to linger | |
| 11 | mobj.linger = 10 -- How long this object will linger | |
| 12 | mobj.tailLenMin = 3 -- Minimum tail length | |
| 13 | mobj.tailLenMax = 10 -- Maximum tail length | |
| 14 | mobj.tailLen = 10 | |
| 15 | mobj.chars = "1234567890-=!@#$%^&*()_+qwertyuiop[]QWERTYUIOP{}asdfghjkl;'\\ASDFGHJKL:\"|zxcvbnm,./ZXCVBNM<>?"
| |
| 16 | mobj.charsLen = mobj.chars:len() | |
| 17 | mobj.currentTail = {"a", "a", "a", "a", "a", "a", "a", "a", "a", "a"}
| |
| 18 | mobj.secretText = {}
| |
| 19 | end | |
| 20 | ||
| 21 | function mobj:new(o, ...) | |
| 22 | - | mobj.skipFrame = 0 |
| 22 | + | |
| 23 | - | mobj.skipFrameMin = 1 |
| 23 | + | |
| 24 | - | mobj.skipFrameMax = 3 |
| 24 | + | |
| 25 | - | mobj.skipFrameMod = -1 |
| 25 | + | |
| 26 | - | mobj.currFrame = 0 |
| 26 | + | |
| 27 | end | |
| 28 | ||
| 29 | ||
| 30 | function mobj:__init(x) | |
| 31 | self.linger = math.random(self.lingerMin, self.lingerMax) | |
| 32 | self.tailLen = math.random(self.tailLenMin, self.tailLenMax) | |
| 33 | self.x = x | |
| 34 | self.y = 1 | |
| 35 | self.nFrame = 1 | |
| 36 | self.currentTail = {}
| |
| 37 | end | |
| 38 | function mobj:randomLinger() | |
| 39 | self.linger = math.random(self.lingerMin, self.lingerMax) | |
| 40 | end | |
| 41 | function mobj:printPos(x, y, sText) | |
| 42 | term.setCursorPos(x, y) | |
| 43 | term.write(sText) | |
| 44 | end | |
| 45 | - | self.skipFrame = math.random(self.skipFrameMin, self.skipFrameMax) + self.skipFrameMod |
| 45 | + | |
| 46 | if self.secretText[y] and self.secretText[y][x] then | |
| 47 | sText = self.secretText[y][x] | |
| 48 | end | |
| 49 | return self:printPos(x, y, sText) | |
| 50 | end | |
| 51 | function mobj:randomChar() | |
| 52 | local r = math.random(1, self.charsLen) | |
| 53 | return string.sub(self.chars, r, r) | |
| 54 | end | |
| 55 | function mobj:printTail() | |
| 56 | for i = 1, self.tailLen do | |
| 57 | if not self.currentTail[i] then break end | |
| 58 | self:printPosT(self.x, self.y - i, self.currentTail[i]) | |
| 59 | end | |
| 60 | end | |
| 61 | ||
| 62 | local termX, termY = term.getSize() | |
| 63 | do | |
| 64 | for y = 1, termY do | |
| 65 | mobj.secretText[y] = {}
| |
| 66 | end | |
| 67 | function mobj:addSecretText(x, y, sText) | |
| 68 | if sText:len() + x > termX then | |
| 69 | -- lolno. | |
| 70 | else | |
| 71 | for i = 1, sText:len() do | |
| 72 | local chr = sText:sub(i, i) | |
| 73 | self.secretText[y][x + i-1] = chr | |
| 74 | end | |
| 75 | end | |
| 76 | end | |
| 77 | function mobj:addSecretTextD(x, y, dir, sText) | |
| 78 | -- 1 = bottomright, 2 = bottomleft, 3 = topright, 4 = topleft | |
| 79 | local xmod = dir %2 == 1 and 1 or -1 | |
| 80 | local ymod = (dir == 1 or dir == 2) and 1 or -1 | |
| 81 | local finalx, finaly = x + (xmod * sText:len()), y + (ymod *sText:len()) | |
| 82 | --print("finalx, finaly", finalx, finaly)
| |
| 83 | --read() | |
| 84 | local cx, cy = x, y | |
| 85 | for i = 1, sText:len() do | |
| 86 | local cx, cy = x + (xmod * (i -1)), y + (ymod * (i -1)) | |
| 87 | if self.secretText[cy] then | |
| 88 | self.secretText[cy][cx] = sText:sub(i, i) | |
| 89 | end | |
| 90 | end | |
| 91 | end | |
| 92 | ||
| 93 | end | |
| 94 | ||
| 95 | function mobj:render() | |
| 96 | self:printTail() | |
| 97 | self.nFrame = self.nFrame + 1 | |
| 98 | if self.nFrame == self.linger then | |
| 99 | table.insert(self.currentTail, 1, self:randomChar()) | |
| 100 | self:printPosT(self.x, self.y, self.currentTail[1]) | |
| 101 | self.y = self.y + 1 | |
| 102 | self.nFrame = 1 | |
| 103 | if self.y > termY + self.tailLen then | |
| 104 | self:__init(self.x) | |
| 105 | end | |
| 106 | - | local sSkip = false |
| 106 | + | |
| 107 | - | if self.currFrame ~= self.skipFrame then |
| 107 | + | self:printPos(self.x, self.y, self:randomChar()) |
| 108 | - | self.currFrame = self.currFrame + 1 |
| 108 | + | |
| 109 | end | |
| 110 | - | self.currFrame = 0 |
| 110 | + | |
| 111 | - | self.nFrame = self.nFrame + 1 |
| 111 | + | |
| 112 | - | if self.nFrame == self.linger then |
| 112 | + | |
| 113 | - | table.insert(self.currentTail, 1, self.lastRandomChar) |
| 113 | + | |
| 114 | - | self:printPosT(self.x, self.y, self.currentTail[1]) |
| 114 | + | |
| 115 | - | self.y = self.y + 1 |
| 115 | + | |
| 116 | - | self.nFrame = 1 |
| 116 | + | |
| 117 | - | if self.y > termY + self.tailLen then |
| 117 | + | |
| 118 | - | self:__init(self.x) |
| 118 | + | |
| 119 | ||
| 120 | - | sSkip = true |
| 120 | + | |
| 121 | function render() | |
| 122 | - | self.lastRandomChar = self:randomChar() |
| 122 | + | |
| 123 | for _, k in pairs(objects) do | |
| 124 | k:render() | |
| 125 | - | if not sSkip then |
| 125 | + | |
| 126 | - | self:printPos(self.x, self.y, self.lastRandomChar) |
| 126 | + | |
| 127 | ||
| 128 | ||
| 129 | ||
| 130 | ||
| 131 | mobj:addSecretTextD(15, 4, 1, "Casper7526") | |
| 132 | mobj:addSecretTextD(18, 4, 1, "made me") | |
| 133 | mobj:addSecretTextD(21, 4, 1, "do this.") | |
| 134 | mobj:addSecretText(15, 15, "Spacebar to exit.") | |
| 135 | init() | |
| 136 | ||
| 137 | ---[[ | |
| 138 | while true do | |
| 139 | local e, p1, p2 = os.pullEvent() | |
| 140 | if e == "timer" and p1 == eventT then | |
| 141 | eventT = os.startTimer(0.05) -- 20 fps | |
| 142 | render() | |
| 143 | elseif e == "key" and p1 == 57 then | |
| 144 | term.clear() | |
| 145 | term.setCursorPos(1,1) | |
| 146 | break | |
| 147 | end | |
| 148 | end | |
| 149 | --]] | |
| 150 | ||
| 151 | --[[for y = 1, termY do | |
| 152 | for x = 1, termX do | |
| 153 | mobj:printPosT(x, y, " ") | |
| 154 | end | |
| 155 | end--]] |