info = { type = "app", title = "Light", author = "BRRRO", license = "MIT", desc = "The frame as a lamp - a few light modes", category = "other", api = 32, } permissions = { "bright" } txt = { mode = "Mode", modes = { "white", "warm", "night light", "plant growth", "fewer insects", "sleep", "red", "green", "blue", "own colour" }, own = "Own colour", own_h = "picking a colour switches the mode to it", lamp = "Brightness", lamp_h = "the frame is a lamp here - the night curve does not apply", label = "Show the name", label_h = "for a few seconds after switching or a change" } for k, v in pairs(({ sk = { mode = "Režim", modes = { "biele", "teplé", "nočné svetlo", "pre rastliny", "menej hmyzu", "spánok", "červené", "zelené", "modré", "vlastná farba" }, own = "Vlastná farba", own_h = "výberom farby sa režim prepne na ňu", lamp = "Jas", lamp_h = "rámik je tu lampa - nočná krivka neplatí", label = "Ukázať meno", label_h = "na pár sekúnd po prepnutí alebo zmene" }, cs = { mode = "Režim", modes = { "bílé", "teplé", "noční světlo", "pro rostliny", "méně hmyzu", "spánek", "červené", "zelené", "modré", "vlastní barva" }, own = "Vlastní barva", own_h = "výběrem barvy se režim přepne na ni", lamp = "Jas", lamp_h = "rámeček je tu lampa - noční křivka neplatí", label = "Ukázat jméno", label_h = "na pár sekund po přepnutí nebo změně" }, })[lang] or {}) do txt[k] = v end local W, H, FPS = gfx.W, gfx.H, gfx.FPS local KEYS = { "white", "warm", "night", "plant", "insect", "sleep", "red", "green", "blue", "own" } local MODES = { white = { r = 255, g = 244, b = 232 }, warm = { r = 255, g = 176, b = 92 }, night = { r = 255, g = 138, b = 44 }, plant = { r = 208, g = 40, b = 232 }, insect = { r = 255, g = 196, b = 0 }, sleep = { r = 180, g = 24, b = 8 }, red = { r = 255, g = 40, b = 30 }, green = { r = 40, g = 235, b = 70 }, blue = { r = 50, g = 110, b = 255 }, } settings = { { key = "mode", type = "int", default = "night", label = txt.mode, opts = { keys = KEYS, table.unpack(txt.modes) } }, { key = "own", type = "color", default = "#FF8A2C", label = txt.own, hint = txt.own_h, also = { key = "mode", value = "own" } }, { key = "lamp", type = "int", min = 5, max = 100, unit = "%", default = 55, label = txt.lamp, hint = txt.lamp_h }, { key = "label", type = "bool", default = true, label = txt.label, hint = txt.label_h }, } local NAME_S, FADE_S = 2.5, 0.7 local O_NAME = { font = "6x10", fit = "4x6", alpha = 1 } local O_PCT = { font = "4x6", alpha = 1 } local CAP, PCT_CAP = gfx.font("6x10").cap, gfx.font("4x6").cap local NAME_DY, PCT_DY = gfx.text_ink("H", O_NAME), gfx.text_ink("5", O_PCT) local NAME = {} for i, k in ipairs(KEYS) do local s = string.upper(txt.modes[i]) local a, b = s:match("^(.*) (%S+)$") NAME[k] = (a and gfx.text_width(s, O_NAME) > W - 2) and { a, b } or { s } end local t0 = 0 function on_settings() panel.bright(cfg.lamp or 55) t0 = frame or 0 end function render() if frame < t0 then t0 = 0 end local m = MODES[cfg.mode] or cfg.own gfx.clear(m.r, m.g, m.b) local s = (frame - t0) / FPS if cfg.label and s < NAME_S then local f = math.min(1, (NAME_S - s) / FADE_S) O_NAME.alpha, O_PCT.alpha = f, f local lines = NAME[cfg.mode] or NAME.own local bh = 2 + #lines * (CAP + 3) + 1 + PCT_CAP + 2 local by = (H - bh) // 2 gfx.blend_rect(0, by, W, bh, 0, 0, 0, 0.55 * f) for i, s in ipairs(lines) do gfx.text_center(by + 2 + (i - 1) * (CAP + 3) - NAME_DY, s, 240, 240, 245, O_NAME) end gfx.text_center(by + bh - 2 - PCT_CAP - PCT_DY, (cfg.lamp or 55) .. " %", 200, 200, 210, O_PCT) end end