April_The_Sergal

messageBoard

Jan 28th, 2026 (edited)
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.40 KB | None | 0 0
  1. -- Monitor Message Cycler with Transitions and Random Colors
  2. -- Supports: fadeUp, fadeDown, fadeLeft, fadeRight, corruption, none, random
  3. -- Colors can be specific, "random", or both "random" (complementary pairs)
  4.  
  5. -- Configuration
  6. local monitorSide = "back" -- Change to your monitor side
  7. local cycleDelay = 3 -- Seconds between messages
  8. local animSpeed = 0.05 -- Animation frame delay
  9.  
  10. -- All available transitions for random selection
  11. local allTransitions = {
  12. "fadeUp",
  13. "fadeDown",
  14. "fadeLeft",
  15. "fadeRight",
  16. "corruption",
  17. "none",
  18. }
  19.  
  20. -- Complementary color pairs for high contrast/visibility
  21. -- Each color maps to colors that provide good contrast
  22. local complementaryColors = {
  23. [colors.white] = {colors.black, colors.gray, colors.blue, colors.purple, colors.red, colors.green, colors.brown, colors.magenta},
  24. [colors.orange] = {colors.black, colors.blue, colors.gray, colors.purple, colors.brown},
  25. [colors.magenta] = {colors.white, colors.black, colors.lime, colors.yellow, colors.lightBlue, colors.lightGray},
  26. [colors.lightBlue] = {colors.black, colors.gray, colors.blue, colors.purple, colors.brown, colors.red},
  27. [colors.yellow] = {colors.black, colors.blue, colors.purple, colors.gray, colors.brown, colors.red, colors.green},
  28. [colors.lime] = {colors.black, colors.gray, colors.blue, colors.purple, colors.brown, colors.red, colors.magenta},
  29. [colors.pink] = {colors.black, colors.gray, colors.blue, colors.purple, colors.brown},
  30. [colors.gray] = {colors.white, colors.yellow, colors.lime, colors.lightBlue, colors.pink, colors.orange, colors.cyan, colors.lightGray},
  31. [colors.lightGray] = {colors.black, colors.blue, colors.purple, colors.brown, colors.red, colors.green},
  32. [colors.cyan] = {colors.black, colors.gray, colors.brown, colors.red, colors.purple},
  33. [colors.purple] = {colors.white, colors.yellow, colors.lime, colors.lightBlue, colors.pink, colors.orange, colors.cyan, colors.lightGray},
  34. [colors.blue] = {colors.white, colors.yellow, colors.lime, colors.lightBlue, colors.pink, colors.orange, colors.cyan, colors.lightGray},
  35. [colors.brown] = {colors.white, colors.yellow, colors.lime, colors.lightBlue, colors.pink, colors.orange, colors.cyan, colors.lightGray},
  36. [colors.green] = {colors.white, colors.yellow, colors.pink, colors.lightGray, colors.lightBlue, colors.magenta},
  37. [colors.red] = {colors.white, colors.yellow, colors.lime, colors.cyan, colors.lightGray, colors.lightBlue},
  38. [colors.black] = {colors.white, colors.yellow, colors.lime, colors.lightBlue, colors.pink, colors.orange, colors.cyan, colors.lightGray, colors.magenta},
  39. }
  40.  
  41. -- All available colors
  42. local allColors = {}
  43. for color, _ in pairs(complementaryColors) do
  44. table.insert(allColors, color)
  45. end
  46.  
  47. -- Messages table: {message, textColor, backgroundColor, transition}
  48. -- Colors can be specific (colors.white) or "random"
  49. -- Transitions: "fadeUp", "fadeDown", "fadeLeft", "fadeRight", "corruption", "none", "random"
  50. local messages = {
  51. {"My Room", colors.white, colors.green, "fadeUp"},
  52. {"Welcome Home", "random", colors.blue, "fadeLeft"},
  53. {"Do Not Disturb", colors.white, "random", "corruption"},
  54. {"Available", "random", "random", "random"},
  55. {"Gaming Mode", colors.purple, colors.black, "fadeRight"},
  56. {"Party Time", "random", "random", "random"},
  57. }
  58.  
  59. -- Find and wrap the monitor
  60. local monitor = peripheral.wrap(monitorSide)
  61. if not monitor then
  62. error("No monitor found on side: " .. monitorSide)
  63. end
  64.  
  65. local w, h = monitor.getSize()
  66.  
  67. -- Corruption characters for glitch effect
  68. local corruptChars = "!@#$%^&*()_+-=[]{}|;:',.<>?/\\`~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
  69.  
  70. -- Helper: get random element from table
  71. local function randomFrom(tbl)
  72. return tbl[math.random(1, #tbl)]
  73. end
  74.  
  75. -- Helper: get random color
  76. local function getRandomColor()
  77. return randomFrom(allColors)
  78. end
  79.  
  80. -- Helper: get complementary color for a given color
  81. local function getComplementaryColor(baseColor)
  82. local complements = complementaryColors[baseColor]
  83. if complements then
  84. return randomFrom(complements)
  85. end
  86. -- Fallback: return a contrasting color
  87. if baseColor == colors.black then
  88. return colors.white
  89. end
  90. return colors.black
  91. end
  92.  
  93. -- Helper: resolve colors ensuring visibility
  94. local function resolveColors(textColorValue, bgColorValue)
  95. local textColor, bgColor
  96.  
  97. -- Both random: pick complementary pair
  98. if textColorValue == "random" and bgColorValue == "random" then
  99. bgColor = getRandomColor()
  100. textColor = getComplementaryColor(bgColor)
  101. -- Only text random: ensure it contrasts with bg
  102. elseif textColorValue == "random" then
  103. bgColor = bgColorValue
  104. textColor = getComplementaryColor(bgColor)
  105. -- Only bg random: ensure it contrasts with text
  106. elseif bgColorValue == "random" then
  107. textColor = textColorValue
  108. bgColor = getComplementaryColor(textColor)
  109. -- Both specified
  110. else
  111. textColor = textColorValue
  112. bgColor = bgColorValue
  113. end
  114.  
  115. return textColor, bgColor
  116. end
  117.  
  118. -- Helper: resolve transition (handles "random")
  119. local function resolveTransition(transitionValue)
  120. if transitionValue == "random" then
  121. return randomFrom(allTransitions)
  122. end
  123. return transitionValue or "none"
  124. end
  125.  
  126. -- Helper: get random corruption character
  127. local function getCorruptChar()
  128. local idx = math.random(1, #corruptChars)
  129. return corruptChars:sub(idx, idx)
  130. end
  131.  
  132. -- Helper: clear screen with color
  133. local function clearScreen(bgColor)
  134. monitor.setBackgroundColor(bgColor)
  135. monitor.clear()
  136. end
  137.  
  138. -- Helper: draw centered text at a specific Y offset
  139. local function drawCenteredAt(text, textColor, bgColor, yOffset)
  140. local x = math.floor((w - #text) / 2) + 1
  141. local y = math.floor(h / 2) + 1 + yOffset
  142.  
  143. if y >= 1 and y <= h then
  144. monitor.setTextColor(textColor)
  145. monitor.setBackgroundColor(bgColor)
  146. monitor.setCursorPos(x, y)
  147. monitor.write(text)
  148. end
  149. end
  150.  
  151. -- Helper: draw text at specific X offset (for horizontal transitions)
  152. local function drawAtXOffset(text, textColor, bgColor, xOffset)
  153. local baseX = math.floor((w - #text) / 2) + 1
  154. local y = math.floor(h / 2) + 1
  155. local x = baseX + xOffset
  156.  
  157. monitor.setTextColor(textColor)
  158. monitor.setBackgroundColor(bgColor)
  159. monitor.setCursorPos(1, y)
  160.  
  161. -- Clear the line first
  162. monitor.write(string.rep(" ", w))
  163.  
  164. -- Draw text at offset position (clipped to screen)
  165. for i = 1, #text do
  166. local charX = x + i - 1
  167. if charX >= 1 and charX <= w then
  168. monitor.setCursorPos(charX, y)
  169. monitor.write(text:sub(i, i))
  170. end
  171. end
  172. end
  173.  
  174. -- Transition: None (instant)
  175. local function transitionNone(newMsg, textColor, bgColor)
  176. clearScreen(bgColor)
  177. drawCenteredAt(newMsg, textColor, bgColor, 0)
  178. end
  179.  
  180. -- Transition: Fade Up
  181. local function transitionFadeUp(oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
  182. local steps = h
  183. for i = 1, steps do
  184. clearScreen(bgColor)
  185. if oldMsg then
  186. drawCenteredAt(oldMsg, oldTextColor, bgColor, -i)
  187. end
  188. drawCenteredAt(newMsg, textColor, bgColor, steps - i)
  189. sleep(animSpeed)
  190. end
  191. clearScreen(bgColor)
  192. drawCenteredAt(newMsg, textColor, bgColor, 0)
  193. end
  194.  
  195. -- Transition: Fade Down
  196. local function transitionFadeDown(oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
  197. local steps = h
  198. for i = 1, steps do
  199. clearScreen(bgColor)
  200. if oldMsg then
  201. drawCenteredAt(oldMsg, oldTextColor, bgColor, i)
  202. end
  203. drawCenteredAt(newMsg, textColor, bgColor, -steps + i)
  204. sleep(animSpeed)
  205. end
  206. clearScreen(bgColor)
  207. drawCenteredAt(newMsg, textColor, bgColor, 0)
  208. end
  209.  
  210. -- Transition: Fade Left
  211. local function transitionFadeLeft(oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
  212. local steps = w
  213. for i = 1, steps do
  214. clearScreen(bgColor)
  215. if oldMsg then
  216. drawAtXOffset(oldMsg, oldTextColor, bgColor, -i)
  217. end
  218. drawAtXOffset(newMsg, textColor, bgColor, steps - i)
  219. sleep(animSpeed)
  220. end
  221. clearScreen(bgColor)
  222. drawCenteredAt(newMsg, textColor, bgColor, 0)
  223. end
  224.  
  225. -- Transition: Fade Right
  226. local function transitionFadeRight(oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
  227. local steps = w
  228. for i = 1, steps do
  229. clearScreen(bgColor)
  230. if oldMsg then
  231. drawAtXOffset(oldMsg, oldTextColor, bgColor, i)
  232. end
  233. drawAtXOffset(newMsg, textColor, bgColor, -steps + i)
  234. sleep(animSpeed)
  235. end
  236. clearScreen(bgColor)
  237. drawCenteredAt(newMsg, textColor, bgColor, 0)
  238. end
  239.  
  240. -- Transition: Corruption (glitch effect)
  241. local function transitionCorruption(oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
  242. local x = math.floor((w - #newMsg) / 2) + 1
  243. local y = math.floor(h / 2) + 1
  244.  
  245. local displayText = oldMsg or string.rep(" ", #newMsg)
  246. local iterations = 15
  247.  
  248. -- Phase 1: Corrupt the old text
  249. for phase = 1, iterations do
  250. clearScreen(bgColor)
  251. monitor.setCursorPos(math.floor((w - #displayText) / 2) + 1, y)
  252.  
  253. local corruptLine = ""
  254. local corruptChance = phase / iterations
  255.  
  256. for i = 1, #displayText do
  257. if math.random() < corruptChance then
  258. corruptLine = corruptLine .. getCorruptChar()
  259. else
  260. corruptLine = corruptLine .. displayText:sub(i, i)
  261. end
  262. end
  263.  
  264. monitor.setTextColor(oldTextColor or textColor)
  265. monitor.setBackgroundColor(bgColor)
  266. monitor.write(corruptLine)
  267. sleep(animSpeed)
  268. end
  269.  
  270. -- Phase 2: Resolve into new text
  271. local revealed = {}
  272. for i = 1, #newMsg do
  273. revealed[i] = false
  274. end
  275.  
  276. for phase = 1, iterations do
  277. clearScreen(bgColor)
  278. monitor.setCursorPos(x, y)
  279.  
  280. local revealChance = phase / iterations
  281. local line = ""
  282.  
  283. for i = 1, #newMsg do
  284. if revealed[i] then
  285. line = line .. newMsg:sub(i, i)
  286. elseif math.random() < revealChance then
  287. revealed[i] = true
  288. line = line .. newMsg:sub(i, i)
  289. else
  290. line = line .. getCorruptChar()
  291. end
  292. end
  293.  
  294. monitor.setTextColor(textColor)
  295. monitor.setBackgroundColor(bgColor)
  296. monitor.write(line)
  297. sleep(animSpeed)
  298. end
  299.  
  300. clearScreen(bgColor)
  301. drawCenteredAt(newMsg, textColor, bgColor, 0)
  302. end
  303.  
  304. -- Main transition handler
  305. local function doTransition(transition, oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
  306. if transition == "fadeUp" then
  307. transitionFadeUp(oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
  308. elseif transition == "fadeDown" then
  309. transitionFadeDown(oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
  310. elseif transition == "fadeLeft" then
  311. transitionFadeLeft(oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
  312. elseif transition == "fadeRight" then
  313. transitionFadeRight(oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
  314. elseif transition == "corruption" then
  315. transitionCorruption(oldMsg, oldTextColor, oldBgColor, newMsg, textColor, bgColor)
  316. else
  317. transitionNone(newMsg, textColor, bgColor)
  318. end
  319. end
  320.  
  321. -- Main loop
  322. local index = 1
  323. local oldMsg, oldTextColor, oldBgColor = nil, nil, nil
  324.  
  325. while true do
  326. local msg = messages[index]
  327. local text = msg[1]
  328. local textColorRaw = msg[2]
  329. local bgColorRaw = msg[3]
  330. local transitionRaw = msg[4] or "none"
  331.  
  332. -- Resolve random values
  333. local textColor, bgColor = resolveColors(textColorRaw, bgColorRaw)
  334. local transition = resolveTransition(transitionRaw)
  335.  
  336. doTransition(transition, oldMsg, oldTextColor, oldBgColor, text, textColor, bgColor)
  337.  
  338. -- Store for next transition
  339. oldMsg = text
  340. oldTextColor = textColor
  341. oldBgColor = bgColor
  342.  
  343. -- Move to next message
  344. index = index % #messages + 1
  345.  
  346. sleep(cycleDelay)
  347. end
Advertisement
Add Comment
Please, Sign In to add comment