Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Achman741 Borrowed This
- --I claim no credit for this
- --[[
- File: matrix
- Purpose: A screensaver that emulates screens from the popular movie The Matrix. *A component of TurtleSHELL*
- Author: da404lewzer
- Project: http://turtlescripts.com/project/gjdh00
- License: Creative Commons Attribution-ShareAlike 3.0 Unported License.
- http://creativecommons.org/licenses/by-sa/3.0/
- Changes:
- 1.0.10 12/10/2012
- + Detached to seperate project
- 1.0.0 11/27/2012
- * Cloned file from texty
- ]]
- --User settings (Overridden by texty.settings if file is found)
- local largeFont = 0.5
- local smallFont = 0.5
- --App-managed variables:
- local tArgs = { ... }
- local mon
- local w, h = 1,1
- local ss_running = true
- local positions = {"top", "bottom", "left", "right", "front", "back"}
- local mons = {}
- local curMsg = {}
- local curColor = {}
- local skipMove = 1
- function getColorMode(monitor)
- if monitor.isColor() then
- return 2
- else
- return 1
- end
- end
- local chars = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z","0","1","2","3","4","5","6","7","8","9", "@", "#", "$", "%", "&", "?", "!", "*"}
- function regen(monID, c)
- len = math.random(2,h/2)
- mons[monID].cols[c] = {length=len, x=c, y=-math.random(1,len), speed=math.random(1,3)}
- end
- function update(monitor, monID)
- mon = monitor
- --if mon then
- w, h = mon.getSize()
- --mon.clear()
- mon.setBackgroundColor(colors.black)
- for c=1, w do
- if mons[monID] then
- col = mons[monID].cols[c]
- if col then
- local x, y, i, flicker
- local colorMode = getColorMode(mon)
- mon.setTextColor(colors.white)
- --tX[monID] = 2
- --tY[monID] = 2
- for ii=col.length, 1, -1 do
- flicker = math.random(1, 3)
- if colorMode == 1 then
- mon.setTextColor(colors.black)
- else
- mon.setTextColor(colors.green)
- end
- local iii = -col.length
- local msgText = chars[math.random(#chars)]
- if math.random(2)==1 then
- msgText = string.upper(msgText)
- end
- mon.setCursorPos(col.x, col.y-ii)
- mon.write(msgText)
- end
- flicker = math.random(1, 3)
- if colorMode == 1 then
- if flicker == 1 then
- mon.setTextColor(colors.black)
- else
- mon.setTextColor(colors.white)
- end
- else
- if flicker == 1 then
- mon.setTextColor(colors.lime)
- elseif flicker == 2 then
- mon.setTextColor(colors.white)
- elseif flicker == 3 then
- mon.setTextColor(colors.green)
- end
- end
- local msgText = chars[math.random(#chars)]
- if math.random(2)==1 then
- msgText = string.upper(msgText)
- end
- mon.setCursorPos(col.x, col.y)
- mon.write(msgText)
- mon.setTextColor(colors.black)
- for ii=0,col.speed do
- mon.setCursorPos(col.x, col.y-col.length-col.speed+ii)
- mon.write(" ")
- end
- if skipMove==0 then
- col.y=col.y+col.speed
- if col.y - col.length - col.speed > h then
- regen(monID, c)
- end
- end
- else
- regen(monID, c)
- end
- else
- regen(monID, c)
- end
- end
- --end
- end
- function updateTemplate(monitor, monID)
- if monitor then
- w,h = monitor.getSize()
- if w and h then
- if not mons[monID] then
- --[[if monitor ~= term then
- if w > 7 and h > 5 then
- monitor.setTextScale(largeFont)
- else
- monitor.setTextScale(smallFont)
- end
- w,h = monitor.getSize()
- end]]
- for c=1, w do
- mons[monID] = {cols={}}
- regen(monID, c)
- end
- end
- update(monitor, monID)
- end
- end
- end
- function updateAll()
- updateTemplate(term, 0)
- for i=1, #positions do
- if peripheral.getType(positions[i]) == "monitor" then
- updateTemplate(peripheral.wrap(positions[i]), i)
- end
- end
- end
- function cleanUp()
- term.clear()
- term.setCursorPos(1,1)
- for i=1, #positions do
- if peripheral.getType(positions[i]) == "monitor" then
- local mon = peripheral.wrap(positions[i])
- if mon then
- mon.setTextScale(1)
- mon.clear()
- mon.setCursorPos(1,1)
- end
- end
- end
- end
- local ss_timer = os.startTimer(0)
- while ss_running do
- local event, p1, p2 = os.pullEvent()
- if event == "key" then
- ss_running = false
- else
- if event == "timer" and p1 == ss_timer then
- ss_timer = os.startTimer(0.05)
- end
- if ss_running then
- updateAll()
- skipMove = skipMove + 1
- if skipMove > 5 then
- skipMove = 0
- end
- end
- end
- end
- cleanUp()
Advertisement
Add Comment
Please, Sign In to add comment