info = { type = "image", title = "Rainbow hearts", category = "patterns", author = "BRRRO", version = "1.0", license = "MIT", desc = "Rainbow hearts float up on a pastel sky", api = 33, } local tr = ({ sk = { ["Hearts"] = "Srdiečka", ["Speed"] = "Rýchlosť", ["Background"] = "Pozadie" }, cs = { ["Hearts"] = "Srdíčka", ["Speed"] = "Rychlost", ["Background"] = "Pozadí" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "count", label = T("Hearts"), type = "int", min = 3, max = 9, default = 7 }, { key = "speed", label = T("Speed"), type = "int", min = 1, max = 3, default = 2 }, { key = "bg", label = T("Background"), type = "color", default = "#9A8CC8" }, } local rect, blit = gfx.rect, gfx.blit_indexed local floor, sin = math.floor, math.sin local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local SHAPES = { { sw = 3, rows = { "...xxxxxx...xxxxxx...", "..xxxxxxxx.xxxxxxxx..", ".xxxxxxxxxxxxxxxxxxx.", "xxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxx", ".xxxxxxxxxxxxxxxxxxx.", "..xxxxxxxxxxxxxxxxx..", "...xxxxxxxxxxxxxxx...", "....xxxxxxxxxxxxx....", ".....xxxxxxxxxxx.....", "......xxxxxxxxx......", ".......xxxxxxx.......", "........xxxxx........", ".........xxx.........", "..........x.........." } }, { sw = 2, rows = { "..xxxx...xxxx..", ".xxxxxx.xxxxxx.", "xxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxx", ".xxxxxxxxxxxxx.", "..xxxxxxxxxxx..", "...xxxxxxxxx...", "....xxxxxxx....", ".....xxxxx.....", "......xxx......", ".......x......." } }, { sw = 1, rows = { ".xx...xx.", "xxxxxxxxx", "xxxxxxxxx", "xxxxxxxxx", ".xxxxxxx.", "..xxxxx..", "...xxx...", "....x...." } }, } local RAIN = { { 255, 40, 50 }, { 255, 140, 30 }, { 255, 230, 40 }, { 50, 210, 70 }, { 40, 140, 255 }, { 90, 70, 230 }, { 180, 70, 220 } } local OUTL = { 96, 34, 98 } for _, S in ipairs(SHAPES) do local P = 7 * S.sw local rows = S.rows local w, h = #rows[1], #rows local out = {} for y = 1, h do local r = {} for x = 1, w do local c = 0 if rows[y]:sub(x, x) == "x" then local function ins(xx, yy) return xx >= 1 and xx <= w and yy >= 1 and yy <= h and rows[yy]:sub(xx, xx) == "x" end if ins(x - 1, y) and ins(x + 1, y) and ins(x, y - 1) and ins(x, y + 1) then c = (x - 1) % P + 1 else c = P + 1 end end r[x] = c end out[y] = string.char(table.unpack(r, 1, w)) end S.grid, S.w, S.h, S.P = table.concat(out), w, h, P S.pals = {} local i = (2 - 1) * w + 3 + (S.sw - 1) S.grid = S.grid:sub(1, i - 1) .. string.char(P + 2) .. S.grid:sub(i + 1) end local function palette(S, shift) local p = S.pals[shift] if p then return p end p = { 0, 0, 0 } for k = 1, S.P do local c = RAIN[((k - 1 + shift) // S.sw) % 7 + 1] local n = #p p[n + 1], p[n + 2], p[n + 3] = c[1], c[2], c[3] end local n = #p p[n + 1], p[n + 2], p[n + 3] = OUTL[1], OUTL[2], OUTL[3] p[n + 4], p[n + 5], p[n + 6] = 255, 255, 255 S.pals[shift] = p return p end local HD = { { 1, 6, 4, 0, 0.0 }, { 2, 42, 3, 40, 1.7 }, { 3, 26, 2, 20, 3.1 }, { 1, 38, 5, 70, 4.2 }, { 2, 12, 3, 100, 2.4 }, { 3, 54, 2, 60, 5.5 }, { 3, 8, 2, 120, 0.9 }, { 2, 28, 4, 90, 3.8 }, { 3, 46, 2, 10, 1.1 }, } local ORDER, NORD = {}, 0 local BGC, SPK = { 154, 140, 200 }, { 214, 206, 238 } local KS = 0 function on_settings() local c = cfg.bg or { r = 154, g = 140, b = 200 } BGC = { c.r, c.g, c.b } SPK = { c.r + (255 - c.r) * 55 // 100, c.g + (255 - c.g) * 55 // 100, c.b + (255 - c.b) * 55 // 100 } KS = (cfg.speed or 2) - 2 local n = cfg.count or 7 ORDER, NORD = {}, 0 for cls = 3, 1, -1 do for i = 1, n do if HD[i][1] == cls then NORD = NORD + 1; ORDER[NORD] = HD[i] end end end end local SX = { 5, 20, 33, 50, 59, 14, 44, 27 } local SY = { 12, 40, 6, 30, 52, 58, 18, 50 } function render() if not ORDER[1] then on_settings() end local t = frame * STEP_HZ // FPS gfx.clear(BGC[1], BGC[2], BGC[3]) for i = 1, #SX do if (t // 4 + i * 5) % 28 < 5 then rect(SX[i] - 1, SY[i], 3, 1, SPK[1], SPK[2], SPK[3]) rect(SX[i], SY[i] - 1, 1, 3, SPK[1], SPK[2], SPK[3]) end end for j = 1, NORD do local d = ORDER[j] local S = SHAPES[d[1]] local k = d[3] - KS if k < 1 then k = 1 end local span = H + S.h + 2 local pos = (t // k + d[4]) % span local x = d[2] + floor(2 * sin(t * 0.04 + d[5]) + 0.5) blit(S.grid, palette(S, (t // 2 + d[4]) % S.P), x, H - pos, S.w, S.h, S.w, S.h, true) end end