Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- File: wubwub
- Purpose: A screensaver that emulates audio meters
- Author: da404lewzer
- Project: http://turtlescripts.com/project/gjdh0b
- License: Creative Commons Attribution-ShareAlike 3.0 Unported License.
- http://creativecommons.org/licenses/by-sa/3.0/
- ]]
- local largeFont = 0.5
- local smallFont = 0.5
- local tArgs = { ... }
- local mon
- local w, h = 1,1
- local ss_running = true
- local mons = {}
- local curMsg = {}
- local curColor = {}
- --colors
- local blues = {colors.blue, colors.cyan, colors.white}
- local greens = {colors.green, colors.lime, colors.white}
- local reds = {colors.red, colors.pink, colors.white}
- local grays = {colors.white, colors.lightGray, colors.gray, colors.black}
- local fire = {colors.white, colors.yellow, colors.orange, colors.red}
- local RedilRed = {colors.cyan, colors.yellow, colors.orange, colors.red}
- local hollow = {colors.black, colors.white}
- local merica = {colors.blue, colors.white, colors.red}
- local wtf = {
- colors.white,
- colors.orange,
- colors.magenta,
- colors.lightBlue,
- colors.yellow,
- colors.lime,
- colors.pink,
- colors.gray,
- colors.lightGray,
- colors.cyan,
- colors.purple,
- colors.blue,
- colors.brown,
- colors.green,
- colors.red
- }
- --basic settings
- local randomize = true
- --these arrays allow you to define all the possible pallets
- local peakChoices = {blues, grays, greens, reds, wtf}
- local barColorChoices = {fire, RedilRed, hollow, merica, greens, blues, reds, grays, wtf}
- --these arrays allow you to specify per-monitor settings
- local positions = {"term", "top", "bottom", "left", "right", "front", "back"} --position/order of the monitor
- local reverse = {false, false, true, false, false, false, false} --this means "flip" the axis
- local horizontal = {true, true, true, false, true, true, true} --true if horizontal, false if vertical
- local peaks = {blues, blues, blues, blues, blues, blues, blues} --which peak colors should we show?
- local barColors = {fire, fire, fire, fire, fire, fire, fire} --which bar colors should we show?
- local columns = {4, 2, 5, 3, 6, 4, 4} --number of columns to render
- local modes = {"stack3", "stack3", "stack3", "stack3", "stack3", "stack3", "stack3"} --how do we paint the bars? "split3", "solid" OR "stack3"
- --do we split the meter down the middle?
- local centered = {true, false, false, false, true, false, false}
- --not settings
- local nextChange, lastClock = {},{}
- local skipMove = 1
- function randomizeMonitor(monitor, monID)
- peaks[monID] = peakChoices[math.random(1,#peakChoices)]
- barColors[monID] = barColorChoices[math.random(1,#barColorChoices)]
- reverse[monID] = math.random(0,1)==1
- horizontal[monID] = math.random(0,1)==1
- centered[monID] = math.random(0,1)==1
- nextChange[monID] = math.random(3,6)
- lastClock[monID] = os.clock()
- end
- 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, s)
- len = math.random(0,math.random(1,s))
- local lastHeight=0
- local lastTime = os.clock()
- if mons[monID].cols[c] then
- lastHeight = mons[monID].cols[c].lastHeight
- lastTime = mons[monID].cols[c].lastTime
- if len > lastHeight then
- lastHeight = len
- lastTime = os.clock()
- end
- if lastHeight > s-1 then
- lastHeight = s-1
- end
- if os.clock() - lastTime > 1 then
- lastHeight=lastHeight-1
- if lastHeight < 0 then
- lastHeight = 0
- end
- end
- end
- mons[monID].cols[c] = {length=len, x=c, y=s, speed=math.random(1,3), lastHeight=lastHeight, lastTime=lastTime}
- end
- function update(monitor, monID)
- mon = monitor
- w, h = mon.getSize()
- local colorMode = getColorMode(mon)
- if colorMode == 1 then
- mon.setBackgroundColor(colors.black)
- else
- mon.setBackgroundColor(colors.black)
- end
- mon.clear()
- if horizontal[monID] then
- local hh = h
- if centered[monID] then hh = h/2 end
- local cols = w / columns[monID]
- local c, lastUpdate = -1
- for cd=0, w-1 do
- c = math.floor(cd/cols)+1
- if lastUpdate ~= c then
- lastUpdate = c
- regen(monID, c, hh)
- end
- if mons[monID] then
- col = mons[monID].cols[c]
- if col then
- local x, y, i
- for ii=0, col.length-1, 1 do
- local y = hh-ii
- if colorMode == 1 then
- mon.setBackgroundColor(colors.white)
- else
- if modes[monID] == "stack3" then
- local tmpPercent = col.length / #barColors[monID]
- for cc=1, #barColors[monID] do
- local curSpot = tmpPercent*(#barColors[monID] - (cc-1))
- if ii < curSpot then
- mon.setBackgroundColor(barColors[monID][#barColors[monID] - (cc-1)])
- end
- end
- elseif modes[monID] == "solid" then
- local tmpPercent = hh / #barColors[monID]
- for cc=1, #barColors[monID] do
- local curSpot = tmpPercent*(#barColors[monID] - (cc-1))
- if col.length < curSpot then
- mon.setBackgroundColor(barColors[monID][#barColors[monID] - (cc-1)])
- end
- end
- elseif modes[monID] == "split3" then
- local tmpPercent = hh / #barColors[monID]
- for cc=1, #barColors[monID] do
- local curSpot = tmpPercent*(#barColors[monID] - (cc-1))
- if ii < curSpot then
- mon.setBackgroundColor(barColors[monID][#barColors[monID] - (cc-1)])
- end
- end
- end
- end
- if reverse[monID] then
- mon.setCursorPos(cd+1, hh - y)
- mon.write(" ")
- if centered[monID] then
- mon.setCursorPos(cd+1, hh + y)
- mon.write(" ")
- end
- else
- mon.setCursorPos(cd+1, y)
- mon.write(" ")
- if centered[monID] then
- mon.setCursorPos(cd+1, hh + (hh-y)+1)
- mon.write(" ")
- end
- end
- end
- local peakY = hh-col.lastHeight
- if colorMode == 1 then
- mon.setBackgroundColor(colors.white)
- else
- local tmpPercent = hh / #peaks[monID]
- for cc=1, #peaks[monID] do
- local curSpot = tmpPercent*(#peaks[monID] - (cc-1))
- if peakY < curSpot then
- mon.setBackgroundColor(peaks[monID][#peaks[monID] - (cc-1)])
- end
- end
- end
- if reverse[monID] then
- mon.setCursorPos(cd+1, hh - peakY)
- mon.write(" ")
- if centered[monID] then
- mon.setCursorPos(cd+1, hh + peakY)
- mon.write(" ")
- end
- else
- mon.setCursorPos(cd+1, peakY)
- mon.write(" ")
- if centered[monID] then
- mon.setCursorPos(cd+1, hh + (hh-peakY)+1)
- mon.write(" ")
- end
- end
- else
- regen(monID, c, hh)
- end
- else
- regen(monID, c, hh)
- end
- end
- else
- local ww = w
- if centered[monID] then ww = w/2 end
- local cols = h / columns[monID]
- local c, lastUpdate = -1
- for rd=0, h-1 do
- c = math.floor(rd/cols)+1
- if lastUpdate ~= c then
- lastUpdate = c
- regen(monID, c, ww)
- end
- if mons[monID] then
- col = mons[monID].cols[c]
- if col then
- local x, y, i
- for ii=0, col.length-1, 1 do
- local y = ww-ii
- if colorMode == 1 then
- mon.setBackgroundColor(colors.white)
- else
- if modes[monID] == "stack3" then
- local tmpPercent = col.length / #barColors[monID]
- for cc=1, #barColors[monID] do
- local curSpot = tmpPercent*(#barColors[monID] - (cc-1))
- if ii < curSpot then
- mon.setBackgroundColor(barColors[monID][#barColors[monID] - (cc-1)])
- end
- end
- elseif modes[monID] == "solid" then
- local tmpPercent = ww / #barColors[monID]
- for cc=1, #barColors[monID] do
- local curSpot = tmpPercent*(#barColors[monID] - (cc-1))
- if col.length < curSpot then
- mon.setBackgroundColor(barColors[monID][#barColors[monID] - (cc-1)])
- end
- end
- elseif modes[monID] == "split3" then
- local tmpPercent = ww / #barColors[monID]
- for cc=1, #barColors[monID] do
- local curSpot = tmpPercent*(#barColors[monID] - (cc-1))
- if ii < curSpot then
- mon.setBackgroundColor(barColors[monID][#barColors[monID] - (cc-1)])
- end
- end
- end
- end
- if reverse[monID] then
- mon.setCursorPos(ww - y, rd+1)
- mon.write(" ")
- if centered[monID] then
- mon.setCursorPos(ww + y, rd+1)
- mon.write(" ")
- end
- else
- mon.setCursorPos(y, rd+1)
- mon.write(" ")
- if centered[monID] then
- mon.setCursorPos(ww + (ww-y), (rd)+1)
- mon.write(" ")
- end
- end
- end
- local peakY = ww-col.lastHeight
- if colorMode == 1 then
- mon.setBackgroundColor(colors.white)
- else
- local tmpPercent = w / #peaks[monID]
- for cc=1, #peaks[monID] do
- local curSpot = tmpPercent*(#peaks[monID] - (cc-1))
- if peakY < curSpot then
- mon.setBackgroundColor(peaks[monID][#peaks[monID] - (cc-1)])
- end
- end
- end
- if reverse[monID] then
- mon.setCursorPos(ww - peakY, rd+1)
- mon.write(" ")
- if centered[monID] then
- mon.setCursorPos(ww + peakY, rd+1)
- mon.write(" ")
- end
- else
- mon.setCursorPos(peakY, rd+1)
- mon.write(" ")
- if centered[monID] then
- mon.setCursorPos(ww + (ww-peakY), (rd)+1)
- mon.write(" ")
- end
- end
- else
- regen(monID, c, w)
- end
- else
- regen(monID, c, w)
- 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
- mons[monID] = {cols={}}
- if randomize then
- randomizeMonitor(monitor, monID)
- end
- end
- if randomize then
- if os.clock() - lastClock[monID] > nextChange[monID] then
- randomizeMonitor(monitor, monID)
- end
- end
- update(monitor, monID)
- end
- end
- end
- function updateAll()
- for i=1, #positions do
- if positions[i] == "term" then
- updateTemplate(term, i)
- elseif peripheral.getType(positions[i]) == "monitor" then
- updateTemplate(peripheral.wrap(positions[i]), i)
- end
- end
- end
- function cleanUp()
- for i=1, #positions do
- if positions[i] == "term" then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- elseif peripheral.getType(positions[i]) == "monitor" then
- local mon = peripheral.wrap(positions[i])
- if mon then
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- 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)
- updateAll()
- end
- end
- end
- cleanUp()
Add Comment
Please, Sign In to add comment