Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Monitor Message Cycler with Transitions and Random Colors
- -- Supports: fadeUp, fadeDown, fadeLeft, fadeRight, corruption, none, random
- -- Colors can be specific, "random", or both "random" (complementary pairs)
- -- Configuration
- local monitorSide = "back" -- Change to your monitor side
- local cycleDelay = 3 -- Seconds between messages
- local animSpeed = 0.05 -- Animation frame delay
- -- All available transitions for random selection
- local allTransitions = {
- "fadeUp",
- "fadeDown",
- "fadeLeft",
- "fadeRight",
- "corruption",
- "none",
- }
- -- Complementary color pairs for high contrast/visibility
- -- Each color maps to colors that provide good contrast
- local complementaryColors = {
- [colors.white] = {colors.black, colors.gray, colors.blue, colors.purple, colors.red, colors.green, colors.brown, colors.magenta},
- [colors.orange] = {colors.black, colors.blue, colors.gray, colors.purple, colors.brown},
- [colors.magenta] = {colors.white, colors.black, colors.lime, colors.yellow, colors.lightBlue, colors.lightGray},
- [colors.lightBlue] = {colors.black, colors.gray, colors.blue, colors.purple, colors.brown, colors.red},
- [colors.yellow] = {colors.black, colors.blue, colors.purple, colors.gray, colors.brown, colors.red, colors.green},
- [colors.lime] = {colors.black, colors.gray, colors.blue, colors.purple, colors.brown, colors.red, colors.magenta},
- [colors.pink] = {colors.black, colors.gray, colors.blue, colors.purple, colors.brown},
- [colors.gray] = {colors.white, colors.yellow, colors.lime, colors.lightBlue, colors.pink, colors.orange, colors.cyan, colors.lightGray},
- [colors.lightGray] = {colors.black, colors.blue, colors.purple, colors.brown, colors.red, colors.green},
- [colors.cyan] = {colors.black, colors.gray, colors.brown, colors.red, colors.purple},
- [colors.purple] = {colors.white, colors.yellow, colors.lime, colors.lightBlue, colors.pink, colors.orange, colors.cyan, colors.lightGray},
- [colors.blue] = {colors.white, colors.yellow, colors.lime, colors.lightBlue, colors.pink, colors.orange, colors.cyan, colors.lightGray},
- [colors.brown] = {colors.white, colors.yellow, colors.lime, colors.lightBlue, colors.pink, colors.orange, colors.cyan, colors.lightGray},
- [colors.green] = {colors.white, colors.yellow, colors.pink, colors.lightGray, colors.lightBlue, colors.magenta},
- [colors.red] = {colors.white, colors.yellow, colors.lime, colors.cyan, colors.lightGray, colors.lightBlue},
- [colors.black] = {colors.white, colors.yellow, colors.lime, colors.lightBlue, colors.pink, colors.orange, colors.cyan, colors.lightGray, colors.magenta},
- }
- -- All available colors
- local allColors = {}
- for color, _ in pairs(complementaryColors) do
- table.insert(allColors, color)
- end
- -- Messages table: {message, textColor, backgroundColor, transition}
- -- Colors can be specific (colors.white) or "random"
- -- Transitions: "fadeUp", "fadeDown", "fadeLeft", "fadeRight", "corruption", "none", "random"
- local messages = {
- {"My Room", colors.white, colors.green, "fadeUp"},
- {"Welcome Home", "random", colors.blue, "fadeLeft"},
- {"Do Not Disturb", colors.white, "random", "corruption"},
- {"Available", "random", "random", "random"},
- {"Gaming Mode", colors.purple, colors.black, "fadeRight"},
- {"Party Time", "random", "random", "random"},
- }
- -- Find and wrap the monitor
- local monitor = peripheral.wrap(monitorSide)
- if not monitor then
- error("No monitor found on side: " .. monitorSide)
- end
- local w, h = monitor.getSize()
- -- Corruption characters for glitch effect
- local corruptChars = "!@#$%^&*()_+-=[]{}|;:',.<>?/\\`~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
- -- Helper: get random element from table
- local function randomFrom(tbl)
- return tbl[math.random(1, #tbl)]
- end
- -- Helper: get random color
- local function getRandomColor()
- return randomFrom(allColors)
- end
- -- Helper: get complementary color for a given color
- local function getComplementaryColor(baseColor)
- local complements = complementaryColors[baseColor]
- if complements then
- return randomFrom(complements)
- end
- -- Fallback: return a contrasting color
- if baseColor == colors.black then
- return colors.white
- end
- return colors.black
- end
- -- Helper: resolve colors ensuring visibility
- local function resolveColors(textColorValue, bgColorValue)
- local textColor, bgColor
- -- Both random: pick complementary pair
- if textColorValue == "random" and bgColorValue == "random" then
- bgColor = getRandomColor()
- textColor = getComplementaryColor(bgColor)
- -- Only text random: ensure it contrasts with bg
- elseif textColorValue == "random" then
- bgColor = bgColorValue
- textColor = getComplementaryColor(bgColor)
- -- Only bg random: ensure it contrasts with text
- elseif bgColorValue == "random" then
- textColor = textColorValue
- bgColor = getComplementaryColor(textColor)
- -- Both specified
- else
- textColor = textColorValue
- bgColor = bgColorValue
- end
- return textColor, bgColor
- end
- -- Helper: resolve transition (handles "random")
- local function resolveTransition(transitionValue)
- if transitionValue == "random" then
- return randomFrom(allTransitions)
- end
- return transitionValue or "none"
- end
- -- Helper: get random corruption character
- local function getCorruptChar()
- local idx = math.random(1, #corruptChars)
- return corruptChars:sub(idx, idx)
- end
- -- Helper: clear screen with color
- local function clearScreen(bgColor)
- monitor.setBackgroundColor(bgColor)
- monitor.clear()
- end
- -- Helper: draw centered text at a specific Y offset
- local function drawCenteredAt(text, textColor, bgColor, yOffset)
- local x = math.floor((w - #text) / 2) + 1
- local y = math.floor(h / 2) + 1 + yOffset
- if y >= 1 and y <= h then
- monitor.setTextColor(textColor)
- monitor.setBackgroundColor(bgColor)
- monitor.setCursorPos(x, y)
- monitor.write(text)
- end
- end
- -- Helper: draw text at specific X offset (for horizontal transitions)
- local function drawAtXOffset(text, textColor, bgColor, xOffset)
- local baseX = math.floor((w - #text) / 2) + 1
- local y = math.floor(h / 2) + 1
- local x = baseX + xOffset
- monitor.setTextColor(textColor)
- monitor.setBackgroundColor(bgColor)
- monitor.setCursorPos(1, y)
- -- Clear the line first
- monitor.write(string.rep(" ", w))
- -- Draw text at offset position (clipped to screen)
- for i = 1, #text do
- local charX = x + i - 1
- if charX >= 1 and charX <= w then
- monitor.setCursorPos(charX, y)
- monitor.write(text:sub(i, i))
- end
- end
- end
- -- Transition: None (instant)
- local function transitionNone(newMsg, textColor, bgColor)
- clearScreen(bgColor)
- drawCenteredAt(newMsg, textColor, bgColor, 0)
- end
- -- Transition: Fade Up
- local function transitionFadeUp(oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
- local steps = h
- for i = 1, steps do
- clearScreen(bgColor)
- if oldMsg then
- drawCenteredAt(oldMsg, oldTextColor, bgColor, -i)
- end
- drawCenteredAt(newMsg, textColor, bgColor, steps - i)
- sleep(animSpeed)
- end
- clearScreen(bgColor)
- drawCenteredAt(newMsg, textColor, bgColor, 0)
- end
- -- Transition: Fade Down
- local function transitionFadeDown(oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
- local steps = h
- for i = 1, steps do
- clearScreen(bgColor)
- if oldMsg then
- drawCenteredAt(oldMsg, oldTextColor, bgColor, i)
- end
- drawCenteredAt(newMsg, textColor, bgColor, -steps + i)
- sleep(animSpeed)
- end
- clearScreen(bgColor)
- drawCenteredAt(newMsg, textColor, bgColor, 0)
- end
- -- Transition: Fade Left
- local function transitionFadeLeft(oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
- local steps = w
- for i = 1, steps do
- clearScreen(bgColor)
- if oldMsg then
- drawAtXOffset(oldMsg, oldTextColor, bgColor, -i)
- end
- drawAtXOffset(newMsg, textColor, bgColor, steps - i)
- sleep(animSpeed)
- end
- clearScreen(bgColor)
- drawCenteredAt(newMsg, textColor, bgColor, 0)
- end
- -- Transition: Fade Right
- local function transitionFadeRight(oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
- local steps = w
- for i = 1, steps do
- clearScreen(bgColor)
- if oldMsg then
- drawAtXOffset(oldMsg, oldTextColor, bgColor, i)
- end
- drawAtXOffset(newMsg, textColor, bgColor, -steps + i)
- sleep(animSpeed)
- end
- clearScreen(bgColor)
- drawCenteredAt(newMsg, textColor, bgColor, 0)
- end
- -- Transition: Corruption (glitch effect)
- local function transitionCorruption(oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
- local x = math.floor((w - #newMsg) / 2) + 1
- local y = math.floor(h / 2) + 1
- local displayText = oldMsg or string.rep(" ", #newMsg)
- local iterations = 15
- -- Phase 1: Corrupt the old text
- for phase = 1, iterations do
- clearScreen(bgColor)
- monitor.setCursorPos(math.floor((w - #displayText) / 2) + 1, y)
- local corruptLine = ""
- local corruptChance = phase / iterations
- for i = 1, #displayText do
- if math.random() < corruptChance then
- corruptLine = corruptLine .. getCorruptChar()
- else
- corruptLine = corruptLine .. displayText:sub(i, i)
- end
- end
- monitor.setTextColor(oldTextColor or textColor)
- monitor.setBackgroundColor(bgColor)
- monitor.write(corruptLine)
- sleep(animSpeed)
- end
- -- Phase 2: Resolve into new text
- local revealed = {}
- for i = 1, #newMsg do
- revealed[i] = false
- end
- for phase = 1, iterations do
- clearScreen(bgColor)
- monitor.setCursorPos(x, y)
- local revealChance = phase / iterations
- local line = ""
- for i = 1, #newMsg do
- if revealed[i] then
- line = line .. newMsg:sub(i, i)
- elseif math.random() < revealChance then
- revealed[i] = true
- line = line .. newMsg:sub(i, i)
- else
- line = line .. getCorruptChar()
- end
- end
- monitor.setTextColor(textColor)
- monitor.setBackgroundColor(bgColor)
- monitor.write(line)
- sleep(animSpeed)
- end
- clearScreen(bgColor)
- drawCenteredAt(newMsg, textColor, bgColor, 0)
- end
- -- Main transition handler
- local function doTransition(transition, oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
- if transition == "fadeUp" then
- transitionFadeUp(oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
- elseif transition == "fadeDown" then
- transitionFadeDown(oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
- elseif transition == "fadeLeft" then
- transitionFadeLeft(oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
- elseif transition == "fadeRight" then
- transitionFadeRight(oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
- elseif transition == "corruption" then
- transitionCorruption(oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
- else
- transitionNone(newMsg, textColor, bgColor)
- end
- end
- -- Main loop
- local index = 1
- local oldMsg, oldTextColor, oldBgColor = nil, nil, nil
- while true do
- local msg = messages[index]
- local text = msg[1]
- local textColorRaw = msg[2]
- local bgColorRaw = msg[3]
- local transitionRaw = msg[4] or "none"
- -- Resolve random values
- local textColor, bgColor = resolveColors(textColorRaw, bgColorRaw)
- local transition = resolveTransition(transitionRaw)
- doTransition(transition, oldMsg, oldTextColor, oldBgColor, text, textColor, bgColor)
- -- Store for next transition
- oldMsg = text
- oldTextColor = textColor
- oldBgColor = bgColor
- -- Move to next message
- index = index % #messages + 1
- sleep(cycleDelay)
- end
Advertisement
Add Comment
Please, Sign In to add comment