info = { type = "image", title = "Lucky tiles", category = "patterns", author = "BRRRO", version = "1.0", license = "MIT", desc = "Tiles flip between hearts and clovers", api = 33, } local tr = ({ sk = { ["Palette"] = "Paleta", ["Candy"] = "Cukrík", ["Pastel"] = "Pastelová", ["Neon"] = "Neón", ["Sunset"] = "Západ slnka", ["Flip speed"] = "Rýchlosť preklápania" }, cs = { ["Palette"] = "Paleta", ["Candy"] = "Bonbon", ["Pastel"] = "Pastelová", ["Sunset"] = "Západ slunce", ["Flip speed"] = "Rychlost překlápění" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "palette", label = T("Palette"), type = "int", default = "candy", opts = { keys = { "candy", "pastel", "neon", "sunset" }, T("Candy"), T("Pastel"), T("Neon"), T("Sunset") } }, { key = "speed", label = T("Flip speed"), type = "int", min = 1, max = 5, default = 3 }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local floor, cos, abs = math.floor, math.cos, math.abs local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local PI = 3.14159265 local PALS = { candy = { { 255, 122, 182 }, { 255, 214, 70 }, { 110, 196, 255 }, { 186, 128, 255 }, { 118, 232, 170 } }, pastel = { { 255, 196, 206 }, { 255, 234, 170 }, { 190, 226, 255 }, { 216, 198, 255 }, { 192, 240, 212 } }, neon = { { 255, 46, 166 }, { 40, 224, 255 }, { 184, 255, 48 }, { 255, 156, 20 }, { 164, 70, 255 } }, sunset = { { 255, 112, 84 }, { 255, 184, 64 }, { 238, 84, 146 }, { 150, 86, 206 }, { 255, 216, 128 } }, } local FLIPS = { 90, 66, 48, 36, 26 } local DUR = 16 local CARD = 30 local POS = { { 1, 1 }, { 33, 1 }, { 33, 33 }, { 1, 33 } } local HEART_TXT = [[ ....oooo....oooo.... ..oohhhso..offffoo.. .ohhffffhooffffffso. .ohffffffhfffffffso. .ohffffffffffffffso. .ohffffffffffffffso. .ohffffffffffffffso. .ohffffffffffffffso. .ohffffffffffffffso. .ohffffffffffffffso. .osffffffffffffffso. ..offfffffffffffso.. ...offfffffffffso... ...osffffffffffso... ....osffffffffso.... .....ossffffsso..... ......oosffsoo...... ........osso........ .........oo......... ....................]] local HEART_BIG_TXT = [[ .....ooo......ooo..... ...oohhhoo..oofffoo... ..ohhfffhhooffffffso.. .ohfffffffhffffffffso. .ohffffffffffffffffso. .ohffffffffffffffffso. .ohffffffffffffffffso. .ohffffffffffffffffso. .ohffffffffffffffffso. .ohffffffffffffffffso. .ohffffffffffffffffso. ..offfffffffffffffso.. ..offfffffffffffffso.. ...offfffffffffffso... ...osffffffffffffso... ....osffffffffffso.... .....osffffffffso..... ......ossffffsso...... .......oosffsoo....... .........osso......... ..........oo.......... ......................]] local CLOVER_TXT = [[ ......ooo....ooo...... .....offso..offso..... .....offfsoofffso..... ...ooffffsoofffffoo... ..offhhffsoofffhhfso.. ..offfhhfsooffhhffso.. ..offffhhsoofhhfffso.. ..ossssshhoohhfffsso.. ...ooooooooosssssoo... .....ooooo..ooooo..... ...ooffffsooooooooo... ..offfffhhoohhffffso.. ..offffhhsoofhhfffso.. ..offfhhfsooffhhffso.. ..osshhffsoofffhhsso.. ...ooffffsoofffffoo... .....offfsoosffso..... .....ossso..ossso..... ......ooo...oooo...... ............ooo....... .............oto...... .............ooo......]] local MAP = { ["."] = "\0", o = "\1", f = "\2", s = "\3", h = "\4", t = "\5" } local function build(txt, pal) local sil, fil, j = {}, {}, 0 for row in txt:gmatch("[^\n]+") do j = j + 1 local sr, fr = {}, {} for a, b in row:gmatch("()[^.]+()") do sr[#sr + 1] = a - 1; sr[#sr + 1] = b - a end for a, b in row:gmatch("()[fsht]+()") do fr[#fr + 1] = a - 1; fr[#fr + 1] = b - a end sil[j], fil[j] = sr, fr end return { cells = txt:gsub("\n", ""):gsub(".", MAP), S = j, pal = pal, sil = sil, fil = fil } end local HPAL = { 0, 0, 0, 92, 12, 38, 236, 40, 72, 184, 18, 52, 255, 214, 226 } local CPAL = { 0, 0, 0, 18, 72, 36, 70, 196, 84, 36, 146, 60, 206, 255, 190, 60, 150, 56 } local HEART, HEART_BIG, CLOVER = build(HEART_TXT, HPAL), build(HEART_BIG_TXT, HPAL), build(CLOVER_TXT, CPAL) local function runs(sp, cx, y0, s, list, r, g, b) local S = sp.S for j = 1, S do local L = list[j] for k = 1, #L, 2 do local i0 = floor(cx + (L[k] - S / 2) * s + 0.5) local i1 = floor(cx + (L[k] + L[k + 1] - S / 2) * s + 0.5) if i1 > i0 then rect(i0, y0 + j - 1, i1 - i0, 1, r, g, b) end end end end local function card(q, s, col, sp) local x0, y0 = POS[q][1], POS[q][2] local r, g, b = col[1], col[2], col[3] local w = floor(CARD * s + 0.5) if w < 3 then rect(x0 + 14, y0 + 1, 2, CARD - 2, (r + 255) // 2, (g + 255) // 2, (b + 255) // 2) return end local xl = x0 + (CARD - w) // 2 rect(xl + 1, y0, w - 2, CARD, r, g, b) rect(xl, y0 + 1, w, CARD - 2, r, g, b) local lr, lg, lb = (r * 5 + 255 * 4) // 9, (g * 5 + 255 * 4) // 9, (b * 5 + 255 * 4) // 9 local dr, dg, db = r * 72 // 100, g * 72 // 100, b * 72 // 100 rect(xl + 1, y0 + 1, w - 2, 1, lr, lg, lb) rect(xl + 1, y0 + 2, 1, CARD - 3, lr, lg, lb) rect(xl + 1, y0 + CARD - 2, w - 2, 1, dr, dg, db) rect(xl + w - 2, y0 + 2, 1, CARD - 4, dr, dg, db) local S = sp.S local sy = y0 + (CARD - S) // 2 if s > 0.995 then gfx.blit_indexed(sp.cells, sp.pal, x0 + (CARD - S) // 2, sy, S, S, S, S, true) else local p = sp.pal local cx = x0 + CARD / 2 runs(sp, cx, sy, s, sp.sil, p[4], p[5], p[6]) runs(sp, cx, sy, s, sp.fil, p[7], p[8], p[9]) end end local function star(x, y, q) if q < 2 or q > 8 then blend(x, y, 255, 255, 255, 0.6); return end px(x, y, 255, 255, 255) if q >= 3 and q <= 7 then px(x - 1, y, 255, 255, 255); px(x + 1, y, 255, 255, 255) px(x, y - 1, 255, 255, 255); px(x, y + 1, 255, 255, 255) end end local PAL, FLIP = PALS.candy, 48 function on_settings() PAL = PALS[cfg.palette] or PALS.candy FLIP = FLIPS[cfg.speed or 3] or 48 end function render() gfx.clear(34, 26, 66) local t = frame * STEP_HZ // FPS local G = t // FLIP for q = 1, 4 do local qq = q - 1 local gl = G - (G - qq) % 4 if gl < 0 then gl = qq - 4 end local p = (t - gl * FLIP) / DUR local face, s = gl, 1 if p < 1 then s = abs(cos(PI * p)) if p < 0.5 then face = gl - 4 end end local col = PAL[face % 5 + 1] local heart = (((face - qq) // 4) + qq) % 2 == 0 local sp if heart then local hb = (t + qq * 11) % 42 sp = (hb < 4 or (hb >= 7 and hb < 11)) and HEART_BIG or HEART else sp = CLOVER end card(q, s, col, sp) local x0, y0 = POS[q][1], POS[q][2] local sh = t - (gl * FLIP + DUR) if sh >= 0 and sh < 18 then gfx.clip(x0, y0, CARD, CARD) for r = 0, CARD - 1, 2 do blend_rect(x0 - 12 + sh * 3 + (CARD - 1 - r) // 2, y0 + r, 3, 2, 255, 255, 255, 0.42) end gfx.clip() end if not heart and p >= 1 then local tq = (t + 37 * q) % 80 if tq < 11 then star(x0 + 24, y0 + 5, tq) end end end end