info = { type = "image", title = "Cactus lights", category = "holidays", author = "BRRRO", version = "1.0", license = "MIT", desc = "Lit-up saguaro, a coyote howls at the moon", api = 33, } local ltr = ({ sk = { ["Lights"] = "Svetielka", ["Pattern"] = "Vzor", ["Classic"] = "Klasické", ["Warm"] = "Teplé", ["Cool"] = "Studené", ["Candy"] = "Cukrové", ["Auto"] = "Striedanie", ["Chase"] = "Beh", ["Wave"] = "Vlna", ["Blink"] = "Blikanie", ["Breathe"] = "Dych" }, cs = { ["Lights"] = "Světýlka", ["Pattern"] = "Vzor", ["Classic"] = "Klasické", ["Warm"] = "Teplé", ["Cool"] = "Studené", ["Candy"] = "Cukrové", ["Auto"] = "Střídání", ["Chase"] = "Běh", ["Wave"] = "Vlna", ["Blink"] = "Blikání", ["Breathe"] = "Dech" }, })[lang] or {} local function LT(s) return ltr[s] or s end settings = { { key = "colors", label = LT("Lights"), type = "int", default = "classic", opts = { keys = { "classic", "warm", "cool", "candy" }, LT("Classic"), LT("Warm"), LT("Cool"), LT("Candy") } }, { key = "show", label = LT("Pattern"), type = "int", default = "auto", opts = { keys = { "auto", "chase", "wave", "alternate", "breathe" }, LT("Auto"), LT("Chase"), LT("Wave"), LT("Blink"), LT("Breathe") } }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local blit_rgb, snapshot, blit_indexed = gfx.blit_rgb, gfx.snapshot, gfx.blit_indexed local floor, sin, sqrt, min = math.floor, math.sin, math.sqrt, math.min local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local SETS = { classic = { { 255, 48, 48 }, { 255, 204, 40 }, { 64, 232, 96 }, { 64, 120, 255 } }, warm = { { 255, 150, 40 }, { 255, 92, 32 }, { 255, 214, 112 }, { 255, 64, 44 } }, cool = { { 84, 152, 255 }, { 120, 232, 255 }, { 192, 172, 255 }, { 240, 246, 255 } }, candy = { { 255, 44, 64 }, { 255, 246, 240 }, { 52, 224, 104 }, { 255, 246, 240 } }, } local K = { [0] = 0.2, 0.55, 1 } local LX, LY, NL = {}, {}, 0 local function lamp(x, y) NL = NL + 1; LX[NL] = x; LY[NL] = y end do local sp = { 0, 1, 2, 3, 2, 1 } for k = 0, 21 do lamp(21 + sp[k % 6 + 1], 55 - 2 * k) end local L = { 19,39, 17,37, 15,39, 13,37, 14,35, 15,33, 13,31, 14,29, 15,27, 14,26, 26,33, 28,31, 30,33, 31,31, 30,29, 29,27, 31,25, 30,23, 29,21, 30,20 } for i = 1, #L, 2 do lamp(L[i], L[i + 1]) end end local LAMP = { [0] = {}, {}, {} } function on_settings() local set = SETS[cfg.colors] or SETS.classic for i = 1, NL do local c = set[(i - 1) % #set + 1] for lv = 0, 2 do LAMP[lv][i] = { floor(c[1] * K[lv]), floor(c[2] * K[lv]), floor(c[3] * K[lv]) } end end end local function level(p, i, t) if p == 1 then local m = (i - floor(t * 12)) % 6 return m < 2 and 2 or (m < 3 and 1 or 0) elseif p == 2 then local s = sin(i * 0.55 - t * 3.2) return s > 0.4 and 2 or (s > -0.3 and 1 or 0) elseif p == 3 then return (i + floor(t * 1.6)) % 2 == 0 and 2 or 0 end local s = sin(t * 2) return s > 0.35 and 2 or (s > -0.35 and 1 or 0) end local SHOW = { chase = 1, wave = 2, alternate = 3, breathe = 4 } local SKY_T, SKY_M, GLOW = { 4, 8, 40 }, { 22, 36, 108 }, { 160, 70, 60 } local FAR, NEAR, MOUND, RIM = { 22, 22, 58 }, { 6, 6, 18 }, { 16, 16, 42 }, { 70, 90, 170 } local BODY, BODY_L, BODY_D = { 30, 84, 70 }, { 64, 136, 104 }, { 16, 46, 56 } local function mix(a, b, t) return floor(a[1] + (b[1] - a[1]) * t + 0.5), floor(a[2] + (b[2] - a[2]) * t + 0.5), floor(a[3] + (b[3] - a[3]) * t + 0.5) end local function disc(cx, cy, r, R, G, B) for dy = -r, r do local hw = floor(sqrt(r * r + 0.5 - dy * dy)) rect(cx - hw, cy + dy, 2 * hw + 1, 1, R, G, B) end end local MX, MY = 53, 12 local CREST = {} for x = 0, W - 1 do local d = (x - 47) / 15 CREST[x] = floor(57 - 7 * math.max(0, 1 - d * d) + 0.5) end local SX, SY, SPH = {}, {}, {} do local k = 0 for i = 1, 120 do if k >= 14 then break end local h = hash32(i * 0x9E3779B1) local x, y = umod(h, W), umod(h >> 8, 34) local dx, dy = x - MX, y - MY if dx * dx + dy * dy > 100 and not (x > 12 and x < 33 and y > 8) then k = k + 1 SX[k], SY[k], SPH[k] = x, y, umod(h >> 16, 628) / 100 end end end local BG local function build() for y = 0, 55 do if y < 36 then rect(0, y, W, 1, mix(SKY_T, SKY_M, y / 35)) else rect(0, y, W, 1, mix(SKY_M, GLOW, min(1, (y - 35) / 10))) end end disc(MX, MY, 8, 30, 50, 130) disc(MX, MY, 6, 44, 70, 160) disc(MX, MY, 4, 240, 238, 214) px(MX - 2, MY - 1, 204, 202, 184); px(MX - 1, MY - 1, 204, 202, 184); px(MX + 1, MY + 2, 204, 202, 184) for x = 0, W - 1 do local top = floor(45 + 2.5 * sin(x * 0.13) + 1.8 * sin(x * 0.31 + 1) + 0.5) rect(x, top, 1, 64 - top, FAR[1], FAR[2], FAR[3]) end for _, x in ipairs({ 5, 35 }) do rect(x, 40, 2, 8, FAR[1], FAR[2], FAR[3]); rect(x - 2, 43, 1, 3, FAR[1], FAR[2], FAR[3]) rect(x - 2, 45, 3, 1, FAR[1], FAR[2], FAR[3]); rect(x + 3, 42, 1, 3, FAR[1], FAR[2], FAR[3]) rect(x + 1, 44, 3, 1, FAR[1], FAR[2], FAR[3]) end for x = 0, W - 1 do rect(x, CREST[x], 1, 64 - CREST[x], MOUND[1], MOUND[2], MOUND[3]) end rect(0, 56, W, 8, NEAR[1], NEAR[2], NEAR[3]) local function col(x, y0, y1, c) rect(x, y0, 1, y1 - y0 + 1, c[1], c[2], c[3]) end col(21, 12, 57, BODY_D); col(22, 12, 57, BODY); col(23, 12, 57, BODY); col(24, 12, 57, BODY_L) rect(22, 10, 2, 2, BODY[1], BODY[2], BODY[3]); px(21, 11, BODY_D[1], BODY_D[2], BODY_D[3]) px(24, 11, BODY_L[1], BODY_L[2], BODY_L[3]) rect(15, 37, 6, 2, BODY[1], BODY[2], BODY[3]); rect(15, 39, 6, 1, BODY_D[1], BODY_D[2], BODY_D[3]) col(13, 27, 39, BODY_D); col(14, 27, 39, BODY); col(15, 27, 36, BODY_L); px(14, 26, BODY[1], BODY[2], BODY[3]) rect(25, 31, 5, 2, BODY[1], BODY[2], BODY[3]); rect(25, 33, 5, 1, BODY_D[1], BODY_D[2], BODY_D[3]) col(29, 21, 33, BODY_D); col(30, 21, 33, BODY); col(31, 21, 33, BODY_L); px(30, 20, BODY[1], BODY[2], BODY[3]) rect(16, 55, 4, 2, 22, 22, 50); rect(26, 56, 5, 1, 22, 22, 50); rect(33, 54, 3, 2, 22, 22, 50) BG = snapshot(0, 0, W, H) end local ART = { { ".........2.2....", ".........122....", "........2111222.", "........11111112", "........1111112.", ".......21112....", ".......11112....", "......211112....", ".....2111112....", ".....1111112....", "....21111112....", "...211111112....", "..21111111112...", ".211111111112...", "2111111112.112..", "1111111112.112..", "1111111112.112..", }, { "..............22", "............2212", "........2..21112", ".......2122112..", ".......111112...", ".......11112....", ".......11112....", "......211112....", ".....2111112....", ".....1111112....", "....21111112....", "...211111112....", "..21111111112...", ".211111111112...", "2111111112.112..", "1111111112.112..", "1111111112.112..", }, { "...........2.2..", "...........2.2..", "...........122..", "..........2112..", "........2.1112..", "........121112..", ".......2111112..", "......211112....", ".....2111112....", ".....1111112....", "....21111112....", "...211111112....", "..21111111112...", ".211111111112...", "2111111112.112..", "1111111112.112..", "1111111112.112..", }, } local CPAL = { 0, 0, 0, 6, 6, 18, RIM[1], RIM[2], RIM[3] } local CELLS, CY = {}, CREST[50] - 16 for p = 1, 3 do CELLS[p] = (table.concat(ART[p]):gsub("%.", "\0"):gsub("%d", function(d) return string.char(tonumber(d)) end)) end local function pose(t) local u = t % 12 if u < 3.4 or u >= 7.9 then return 1 end if u < 3.9 or u >= 7.4 then return 2 end return 3 end function render() if not BG then build() end blit_rgb(BG, 0, 0, W, H) local t = frame / FPS local a = t * 2.1 for k = 1, #SX do if sin(a + SPH[k] * 3) > -0.3 then px(SX[k], SY[k], 200, 210, 255) else px(SX[k], SY[k], 80, 92, 150) end end local m = frame % 330 if m < 16 then local hx, hy = 6 + m * 2.4, 3 + m * 0.9 px(floor(hx), floor(hy), 240, 244, 255) blend_rect(floor(hx - 2.4), floor(hy - 0.9), 1, 1, 200, 210, 255, 0.6) blend_rect(floor(hx - 4.8), floor(hy - 1.8), 1, 1, 200, 210, 255, 0.3) end blit_indexed(CELLS[pose(t)], CPAL, 43, CY, 16, 17, 16, 17, true) local p = SHOW[cfg.show] or (floor(t / 7) % 4 + 1) for i = 1, NL do local lv = level(p, i, t) local c = LAMP[lv][i] if lv == 2 then blend_rect(LX[i] - 1, LY[i] - 1, 3, 3, c[1], c[2], c[3], 0.2) end px(LX[i], LY[i], c[1], c[2], c[3]) end end