Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define all presets
- local presets = {
- default = {
- {colors.white, 0xf0f0f0}, {colors.orange, 0xf2b233}, {colors.magenta, 0xe57fd8},
- {colors.lightBlue, 0x99b2f2}, {colors.yellow, 0xdede6c}, {colors.lime, 0x7fcc19},
- {colors.pink, 0xf2b2cc}, {colors.gray, 0x4c4c4c}, {colors.lightGray, 0x999999},
- {colors.cyan, 0x4c99b2}, {colors.purple, 0xb266e5}, {colors.blue, 0x3366cc},
- {colors.brown, 0x7f664c}, {colors.green, 0x57a64e}, {colors.red, 0xcc4c4c},
- {colors.black, 0x111111}
- },
- inverted = {
- {colors.white, 0x111111}, {colors.black, 0xf0f0f0}, {colors.gray, 0x999999},
- {colors.lightGray, 0x4c4c4c}, {colors.orange, 0xf2b233}, {colors.magenta, 0xe57fd8},
- {colors.lightBlue, 0x99b2f2}, {colors.yellow, 0xdede6c}, {colors.lime, 0x7fcc19},
- {colors.pink, 0xf2b2cc}, {colors.cyan, 0x4c99b2}, {colors.purple, 0xb266e5},
- {colors.blue, 0x3366cc}, {colors.brown, 0x7f664c}, {colors.green, 0x57a64e},
- {colors.red, 0xcc4c4c}
- },
- rgb = {
- {colors.white, 0xffffff}, {colors.orange, 0xff7f00}, {colors.magenta, 0xbe00ff},
- {colors.lightBlue, 0x7f7fff}, {colors.yellow, 0xffff00}, {colors.lime, 0x00ff00},
- {colors.pink, 0xff00ff}, {colors.gray, 0x555555}, {colors.lightGray, 0xbebebe},
- {colors.cyan, 0x007fff}, {colors.purple, 0x5500ff}, {colors.blue, 0x0000ff},
- {colors.brown, 0x7f4000}, {colors.green, 0x007f00}, {colors.red, 0xff0000},
- {colors.black, 0x000000}
- },
- retro = {
- {colors.white, 0xf4f4f4}, {colors.orange, 0xef7d57}, {colors.magenta, 0x566c86},
- {colors.lightBlue, 0x41a6f6}, {colors.yellow, 0xffcd75}, {colors.lime, 0xa7f070},
- {colors.pink, 0x94b0c2}, {colors.gray, 0x505050}, {colors.lightGray, 0xb0b0b0},
- {colors.cyan, 0x3e82e0}, {colors.purple, 0x333c57}, {colors.blue, 0x3b5dc9},
- {colors.brown, 0x7f664c}, {colors.green, 0x38b764}, {colors.red, 0xb13e53},
- {colors.black, 0x151515}
- },
- hacker = {
- {colors.white, 0x00ff00}, {colors.orange, 0x00ff00}, {colors.magenta, 0x00ec05},
- {colors.lightBlue, 0x00da09}, {colors.yellow, 0x00ff00}, {colors.lime, 0x00c70e},
- {colors.pink, 0x00b513}, {colors.gray, 0x006000}, {colors.lightGray, 0x00b000},
- {colors.cyan, 0x00a217}, {colors.purple, 0x00901c}, {colors.blue, 0x003333},
- {colors.brown, 0x007d20}, {colors.green, 0x006b25}, {colors.red, 0x00582a},
- {colors.black, 0x001100}
- }
- }
- -- Function to generate a random palette
- local function generateRandomPalette()
- local keys = {
- 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, colors.black
- }
- local palette = {}
- for _, color in ipairs(keys) do
- table.insert(palette, {color, math.random(0, 0xFFFFFF)})
- end
- return palette
- end
- -- Set palette on term and write to file
- local function applyPalette(preset)
- local file = fs.open("/startup/paletteSetter.lua", "w")
- for _, pair in ipairs(preset) do
- local color, hex = table.unpack(pair)
- term.setPaletteColor(color, hex)
- file.writeLine("term.setPaletteColor("..color..", "..hex..")")
- end
- file.close()
- end
- -- Flashing colors on monitor loop
- local function startFlashing(palette, monitor)
- monitor.setTextScale(1)
- monitor.clear()
- while true do
- for _, pair in ipairs(palette) do
- monitor.setBackgroundColor(pair[1])
- monitor.clear()
- sleep(0.4)
- end
- end
- end
- -- Setup
- local monitor = peripheral.wrap("top")
- if not monitor then
- print("No monitor on top!")
- return
- end
- monitor.setTextScale(1)
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.white)
- monitor.clear()
- local options = {"default", "inverted", "rgb", "retro", "hacker", "random"}
- -- Draw menu
- for i, name in ipairs(options) do
- monitor.setCursorPos(2, i + 1)
- monitor.write("[" .. name .. "]")
- end
- -- Wait for touch
- while true do
- local event, side, x, y = os.pullEvent("monitor_touch")
- local choice = options[y - 1]
- if choice then
- local selected = choice == "random" and generateRandomPalette() or presets[choice]
- applyPalette(selected)
- monitor.setTextScale(1)
- monitor.clear()
- startFlashing(selected, monitor)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement