info = { type = "image", title = "Moss card", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "Collectible card of a one-eyed moss monster", api = 44, } local tr = ({ sk = { ["Frame"] = "Rám", ["Blossom"] = "Kvet", ["Foil sheen"] = "Lesk fólie", ["Card number"] = "Číslo karty" }, cs = { ["Frame"] = "Rám", ["Blossom"] = "Květ", ["Foil sheen"] = "Lesk fólie", ["Card number"] = "Číslo karty" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "frame", label = T("Frame"), type = "color", default = "#9A8CC8" }, { key = "flower", label = T("Blossom"), type = "color", default = "#D2283C" }, { key = "foil", label = T("Foil sheen"), type = "bool", default = true }, { key = "num", label = T("Card number"), type = "int", min = 1, max = 999, default = 3 }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local floor, sqrt, sin = math.floor, math.sqrt, math.sin local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local function c3(c) return c[1], c[2], c[3] end local PANEL, WIN, WIN_EDGE = { 30, 24, 58 }, { 14, 12, 30 }, { 62, 52, 104 } local MOSS_T, MOSS_B, MOSS_RIM = { 82, 120, 54 }, { 40, 66, 32 }, { 26, 44, 26 } local HALO, SOCKET = { 98, 136, 60 }, { 20, 36, 24 } local STEM, LEAF, LEAF_L = { 44, 78, 34 }, { 66, 112, 48 }, { 100, 146, 62 } local EYE_Y = 34 local function disc(cx, cy, r, c) for y = floor(cy - r), floor(cy + r - 0.001) do local d = y + 0.5 - cy local hw = floor(sqrt(r * r - d * d) + 0.5) if hw > 0 then rect(cx - hw, y, 2 * hw, 1, c3(c)) end end end local function icon(x, y, rows, pal) for j = 1, #rows do local r = rows[j] for i = 1, #r do local c = pal[r:sub(i, i)] if c then px(x + i - 1, y + j - 1, c3(c)) end end end end local BODY_TOP, BODY_BOT = 22, 46 local HW = {} for y = BODY_TOP, BODY_BOT do if y <= 38 then local u = (38 - y) / 16.5 HW[y] = math.max(8, floor(21 * sqrt(1 - u * u) + 0.5)) else HW[y] = ({ [44] = 20, [45] = 19, [46] = 17 })[y] or 21 end end local BG, STAGE, IRIS, SHEEN = nil, 0, nil, nil local FR, FD, FLOWER = nil, nil, nil local function card_stage() local fc = cfg.frame or { r = 154, g = 140, b = 200 } FR = { fc.r, fc.g, fc.b } FD = { floor(fc.r * 0.45), floor(fc.g * 0.45), floor(fc.b * 0.45) } local fl = cfg.flower or { r = 210, g = 40, b = 60 } FLOWER = { fl.r, fl.g, fl.b } rect(0, 0, W, H, c3(FR)) for _, p in ipairs({ { 0, 0 }, { 1, 0 }, { 0, 1 } }) do px(p[1], p[2], 6, 4, 12); px(63 - p[1], p[2], 6, 4, 12) px(p[1], 63 - p[2], 6, 4, 12); px(63 - p[1], 63 - p[2], 6, 4, 12) end rect(2, 2, 60, 60, c3(FD)) rect(3, 3, 58, 58, c3(PANEL)) rect(4, 9, 56, 44, c3(WIN_EDGE)) rect(5, 10, 54, 42, c3(WIN)) icon(5, 3, { "...GG", "..GGG", ".GGG.", "GGG..", "G...." }, { G = { 96, 156, 66 } }) icon(54, 3, { "..Y..", ".YYY.", "YYYYY", ".YYY.", ".Y.Y." }, { Y = { 236, 194, 72 } }) for i = 0, 3 do local x = 23 + i * 5 local c = i < 3 and { 236, 194, 72 } or { 70, 60, 110 } px(x + 1, 4, c3(c)); rect(x, 5, 3, 1, c3(c)); px(x + 1, 6, c3(c)) end icon(5, 54, { "..B..", ".BBB.", "BBBBB", "BBBBB", ".BBB." }, { B = { 90, 150, 230 } }) icon(54, 54, { "..B..", ".BBB.", "BBBBB", "BBBBB", ".BBB." }, { B = { 90, 150, 230 } }) rect(22, 54, 20, 7, 14, 10, 30) local s = string.format("%03d", cfg.num or 3) local top = gfx.text_ink(s, { font = "3x5" }) gfx.text(22, 55 - top, s, 236, 214, 150, { font = "3x5", w = 20, align = "center" }) BG = gfx.snapshot(0, 0, W, H) end local function creature_stage() gfx.blit_rgb(BG, 0, 0, W, H) for y = BODY_TOP, BODY_BOT do local hw = HW[y] local t = (y - BODY_TOP) / (BODY_BOT - BODY_TOP) rect(32 - hw, y, 2 * hw, 1, c3(MOSS_RIM)) rect(33 - hw, y, 2 * hw - 2, 1, floor(MOSS_T[1] + (MOSS_B[1] - MOSS_T[1]) * t + 0.5), floor(MOSS_T[2] + (MOSS_B[2] - MOSS_T[2]) * t + 0.5), floor(MOSS_T[3] + (MOSS_B[3] - MOSS_T[3]) * t + 0.5)) end for i = 0, 5 do local cx = 32 + (i % 2 == 0 and -1 or 1) * (3 + 6 * (i // 2)) rect(cx - 3, 47, 6, 1, c3(MOSS_B)); rect(cx - 2, 48, 4, 1, c3(MOSS_B)); rect(cx - 1, 49, 2, 1, c3(MOSS_RIM)) px(cx - 3, 47, c3(MOSS_RIM)); px(cx + 2, 47, c3(MOSS_RIM)) end for i = 1, 90 do local h = hash32(i * 0x9E3779B1) local y = BODY_TOP + 3 + umod(h, BODY_BOT - BODY_TOP - 3) local x = 32 - HW[y] + 2 + umod(h >> 8, 2 * HW[y] - 4) local dx, dy = x - 31.5, y - EYE_Y + 0.5 if dx * dx + dy * dy > 14 * 14 then px(x, y, 92, 134, 60); px(x, y + 1, 34, 58, 30) end end local cy = EYE_Y disc(32, cy, 14, HALO) disc(32, cy, 12, SOCKET) disc(32, cy, 10, { 170, 154, 108 }) disc(31, cy - 1, 9, { 204, 190, 142 }) disc(30, cy - 2, 7, { 230, 220, 176 }) BG = gfx.snapshot(0, 0, W, H) end local function build_iris() local rows = {} for y = -5, 5 do for x = -5, 5 do local d2 = x * x + y * y local v = 0 if d2 <= 30 then v = 1 end if d2 <= 12 then v = 2 end if (x == 1 or x == 2) and (y == -2 or y == -1) then v = 3 end rows[#rows + 1] = string.char(v) end end IRIS = table.concat(rows) end local IRIS_PAL = { 0, 0, 0, 150, 160, 56, 10, 10, 16, 255, 255, 255 } local LOOK = { { 0, 0, 50 }, { -3, 0, 60 }, { -3, -1, 25 }, { 0, 0, 40 }, { 3, 1, 55 }, { 3, -2, 30 }, { 0, 2, 25 }, { 0, 0, 55 } } local LOOK_LEN = 0 for i = 1, #LOOK do LOOK_LEN = LOOK_LEN + LOOK[i][3] end local BLINK = { 0.25, 0.7, 1, 1, 0.7, 0.25 } local BLINKS = { 95, 205, 219, 280 } local function look(f) f = f % LOOK_LEN local i = 1 while f >= LOOK[i][3] do f = f - LOOK[i][3]; i = i + 1 end local a, b = LOOK[(i - 2) % #LOOK + 1], LOOK[i] local k = f < 4 and (f + 1) / 5 or 1 return floor(a[1] + (b[1] - a[1]) * k + 0.5), floor(a[2] + (b[2] - a[2]) * k + 0.5) end local function lid(k) local up, lo = floor(k * 13 + 0.5), floor(k * 7 + 0.5) for y = 24, 23 + up do local d = y + 0.5 - 34 local hw = floor(sqrt(100 - d * d) + 0.5) rect(32 - hw, y, 2 * hw, 1, c3(y == 23 + up and MOSS_RIM or HALO)) end for y = 44 - lo, 43 do local d = y + 0.5 - 34 local hw = floor(sqrt(100 - d * d) + 0.5) rect(32 - hw, y, 2 * hw, 1, c3(y == 44 - lo and MOSS_RIM or HALO)) end end local function sprout(bx, by, h, sway, flower) local x0, x1, x2 = bx, bx + floor(sway * 0.4 + 0.5), bx + sway local m = h // 2 rect(x0, by - m, 1, m, c3(STEM)) rect(x1, by - h + 2, 1, h - m - 2 + 1, c3(STEM)) rect(x2, by - h + 1, 1, 2, c3(STEM)) rect(x1 - 2, by - m - 1, 2, 2, c3(LEAF)); px(x1 - 2, by - m - 1, c3(LEAF_L)) rect(x1 + 1, by - m - 3, 2, 2, c3(LEAF)); px(x1 + 2, by - m - 3, c3(LEAF_L)) if flower then local ty = by - h rect(x2 - 1, ty, 3, 1, c3(FLOWER)); rect(x2, ty - 1, 1, 3, c3(FLOWER)) px(x2, ty, 255, 210, 100) else rect(x2 - 1, by - h - 1, 3, 2, c3(LEAF)); px(x2 - 1, by - h - 1, c3(LEAF_L)) end end local SWAY = { -1, 0, 1, 0 } local BW, SKEW = 14, 31 local function build_sheen() local band = {} for i = 0, BW - 1 do band[i + 1] = string.char(floor(255 * (1 - math.abs(i - (BW - 1) / 2) / (BW / 2)) + 0.5)) end band = table.concat(band) local rows = {} for y = 0, 61 do local sh = (61 - y) // 2 rows[y + 1] = string.rep("\0", sh) .. band .. string.rep("\0", BW + SKEW - BW - sh) end SHEEN = table.concat(rows) end local SPECK = {} for i = 1, 6 do local h = hash32(i * 0x85EBCA6B) SPECK[i] = { x = 8 + umod(h, 48), v = 2 + umod(h >> 6, 30) / 10, y = umod(h >> 12, 42), ph = umod(h >> 18, 628) / 100 } end function on_settings() STAGE = 0 end function render() if STAGE == 0 then card_stage(); STAGE = 1; gfx.ready(false) elseif STAGE == 1 then creature_stage(); STAGE = 2 else gfx.blit_rgb(BG, 0, 0, W, H) end if not IRIS then build_iris() end local t = frame / FPS for i = 1, #SPECK do local s = SPECK[i] local y = 51 - (s.y + s.v * t) % 41 local iy = floor(y) local f = y - iy local x = s.x + floor(1.5 * sin(t * 0.8 + s.ph) + 0.5) blend(x, iy, 200, 232, 140, 0.5 * (1 - f)) blend(x, iy + 1, 200, 232, 140, 0.5 * f) end local lx, ly = look(frame) gfx.blit_indexed(IRIS, IRIS_PAL, 26 + lx, 28 + ly, 11, 11, 11, 11, true) local fb = frame % LOOK_LEN for i = 1, #BLINKS do local k = fb - BLINKS[i] + 1 if k >= 1 and k <= #BLINK * 2 then lid(BLINK[(k - 1) // 2 + 1]) end end local pose = floor(t / 0.45) sprout(22, 25, 11, SWAY[pose % 4 + 1] * 2, true) sprout(32, 23, 9, SWAY[(pose + 1) % 4 + 1], false) sprout(42, 25, 11, SWAY[(pose + 2) % 4 + 1] * 2, true) if cfg.foil ~= false then local c = floor(frame % 210) if c < 42 then if not SHEEN then build_sheen() end local x = -(BW + SKEW) + floor(c * (W + BW + SKEW) / 42) gfx.blend_mask(SHEEN, 226, 238, 255, x, 1, BW + SKEW, 62, BW + SKEW, 62, 0.36) end end end