info = { type = "image", title = "Balloon dog", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "A balloon dog sways on its string by a cake", api = 33, } local tr = ({ sk = { ["Dog colour"] = "Farba psa", ["Sparkles"] = "Iskričky" }, cs = { ["Dog colour"] = "Barva psa", ["Sparkles"] = "Jiskřičky" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "dog", label = T("Dog colour"), type = "color", default = "#B48CF0" }, { key = "sparkle", label = T("Sparkles"), type = "bool", default = true }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local floor, sin, exp = math.floor, math.sin, math.exp local hash32, umod = math.hash32, math.umod local byte, char, concat, unpack = string.byte, string.char, table.concat, table.unpack local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local TAU, PI = 6.28318, 3.14159 local WALL, DOT = { 194, 232, 216 }, { 216, 244, 232 } local TABLE, DROP = { 248, 240, 228 }, { 230, 216, 200 } local HEM = { 240, 176, 192 } local PLATE, PRIM = { 214, 232, 250 }, { 166, 198, 236 } local PSHADOW = { 226, 214, 200 } local CREAM, CREAM_S = { 255, 250, 242 }, { 234, 224, 214 } local TOPC = { 255, 252, 248 } local SPONGE, SPONGE_S, SPONGE_D = { 246, 214, 140 }, { 222, 188, 116 }, { 222, 180, 106 } local BERRY, BERRY_D, PINK = { 226, 44, 64 }, { 186, 28, 48 }, { 246, 140, 150 } local LEAF, SEED = { 72, 168, 82 }, { 250, 222, 120 } local STRING = { 120, 110, 130 } local BOW = { 236, 96, 140 } local GLINT = { 255, 252, 220 } local function c3(c) return c[1], c[2], c[3] end local DOG = { "........LD.LD.............", "........DD.DD.............", "........DD.DD.............", "........Dd.Dd.............", "......DDDDDDDD............", ".....DHDDDDDDDd...........", ".DDDDDLDEDDDDDd.......LD..", "DHLDDDDDDDDDDDd.......DD..", "DDDDDDDDDDDDDDd......DDd..", ".dddddDDDDDDDd.......DD...", "......dDDDDDd.......DDd...", "..........DDDD.....DDd....", "..........DLHDDDDDDDDDDd..", ".........DDLDDDDDDDDDDDDd.", ".........DDDDDDDDDDDDDDDd.", "..........dDDddddddDDDDd..", "..........DLdD.....DLdD...", "..........DDdD.....DDdD...", "..........DDdD.....DDdD...", "..........DDdD.....DDdD...", "..........DDdD.....DDdD...", "..........dddd.....dddd...", } local MAP = { ["."] = "\0", D = "\1", d = "\2", L = "\3", H = "\4", E = "\5" } local DW, DH = #DOG[1], #DOG local CELLS do local t = {} for i = 1, DH do t[i] = (DOG[i]:gsub(".", MAP)) end CELLS = concat(t) end local ATX = 11.5 local PAL = {} local KR, KG, KB = 255, 0, 255 local NP = 4 local RAS, built = {}, false local function shift_x(f) local out, row = {}, {} local g = 1 - f local br, bg, bb = c3(WALL) for y = 0, DH - 1 do local base, k = y * DW, 0 for x = 0, DW do local a = (x >= 1 and f > 0) and byte(CELLS, base + x) or 0 local b = (x < DW and g > 0) and byte(CELLS, base + x + 1) or 0 local r1, g1, b1 = KR, KG, KB if a ~= 0 or b ~= 0 then local ar, ag, ab, cr, cg, cb = br, bg, bb, br, bg, bb if a ~= 0 then ar, ag, ab = PAL[3 * a - 2], PAL[3 * a - 1], PAL[3 * a] end if b ~= 0 then cr, cg, cb = PAL[3 * b - 2], PAL[3 * b - 1], PAL[3 * b] end r1 = floor(ar * f + cr * g + 0.5) g1 = floor(ag * f + cg * g + 0.5) b1 = floor(ab * f + cb * g + 0.5) end row[k + 1], row[k + 2], row[k + 3] = r1, g1, b1 k = k + 3 end out[y + 1] = char(unpack(row, 1, k)) end return concat(out) end local BERRIES = { { 11, 23 }, { 21, 24 } } local DOLLOPS = { 7, 17, 27 } local function berry(x, y) rect(x + 1, y, 3, 1, c3(LEAF)); px(x + 2, y - 1, c3(LEAF)) rect(x, y + 1, 5, 3, c3(BERRY)) rect(x + 1, y + 4, 3, 1, c3(BERRY)) px(x + 2, y + 5, c3(BERRY_D)) rect(x + 4, y + 2, 1, 2, c3(BERRY_D)) px(x + 1, y + 2, c3(SEED)); px(x + 3, y + 1, c3(SEED)); px(x + 2, y + 3, c3(SEED)) end local BG = nil local function build_bg() rect(0, 0, W, 42, c3(WALL)) for j = 0, 2 do for i = 0, 3 do rect(2 + i * 8 + (j % 2) * 4, 2 + j * 7, 2, 2, c3(DOT)) end end rect(0, 42, W, 16, c3(TABLE)) rect(0, 58, W, H - 58, c3(DROP)) rect(0, 60, W, 1, c3(HEM)) rect(5, 54, 33, 1, c3(PSHADOW)) for y = 45, 53 do local d = (y + 0.5 - 49.5) / 4.5 local hw = 18 * math.sqrt(1 - d * d) local x0 = floor(21.5 - hw + 0.5) local w = floor(2 * hw + 0.5) rect(x0, y, w, 1, c3(PRIM)) if hw > 3 and y > 45 and y < 53 then rect(x0 + 2, y, w - 4, 1, c3(PLATE)) end end rect(11, 30, 22, 1, c3(TOPC)); rect(10, 31, 22, 1, c3(TOPC)); rect(9, 32, 22, 1, c3(TOPC)) rect(9, 33, 22, 2, c3(CREAM)) rect(9, 35, 22, 4, c3(SPONGE)) rect(9, 39, 22, 3, c3(CREAM)) for k = 0, 3 do local x = 10 + k * 5 rect(x, 39, 3, 2, c3(BERRY)); px(x + 1, 39, c3(PINK)) end rect(9, 42, 22, 6, c3(SPONGE)) rect(9, 48, 22, 1, c3(SPONGE_D)) rect(31, 31, 2, 4, c3(CREAM_S)); rect(31, 35, 2, 4, c3(SPONGE_S)) rect(31, 39, 2, 3, c3(CREAM_S)); rect(31, 42, 2, 7, c3(SPONGE_S)) rect(32, 30, 1, 1, c3(CREAM_S)) for i = 1, #BERRIES do berry(BERRIES[i][1], BERRIES[i][2]) end rect(43, 48, 1, 2, c3(BOW)); rect(46, 48, 1, 2, c3(BOW)); px(44, 49, c3(BOW)); px(45, 49, c3(BOW)) BG = gfx.snapshot(0, 0, W, H) end local SPARK = true function on_settings() local c = cfg.dog or { r = 180, g = 140, b = 240 } PAL = { c.r, c.g, c.b, floor(c.r * 0.72), floor(c.g * 0.72), floor(c.b * 0.78), floor(c.r + (255 - c.r) * 0.4), floor(c.g + (255 - c.g) * 0.4), floor(c.b + (255 - c.b) * 0.4), 255, 255, 255, 60, 36, 84 } RAS, built = {}, false SPARK = cfg.sparkle ~= false end local AX, AY, LEN = 44.5, 49, 18 local DY = AY - LEN - DH local OM = TAU / (3.4 * STEP_HZ) local function draw_dollops(t) local te = ((OM * t - PI / 2) % PI) / OM for i = 1, #DOLLOPS do local x = DOLLOPS[i] local d = te - (i - 1) * 2 local w = 0 if d > 0 then local v = 1.4 * exp(-d / 10) * sin(d * TAU / 7) w = v > 0.5 and 1 or (v < -0.5 and -1 or 0) end rect(x, 28, 4, 2, c3(TOPC)) px(x + 3, 29, c3(CREAM_S)) if w > 0 then rect(x, 27, 3, 1, c3(TOPC)) elseif w < 0 then rect(x + 1, 26, 2, 2, c3(TOPC)) else rect(x + 1, 27, 2, 1, c3(TOPC)) end end end local function star(x, y, k, r, g, b) local a = k < 0.5 and k * 2 or (1 - k) * 2 blend(x, y, r, g, b, a) if a > 0.35 then local s = a * 0.8 blend(x - 1, y, r, g, b, s); blend(x + 1, y, r, g, b, s) blend(x, y - 1, r, g, b, s); blend(x, y + 1, r, g, b, s) end if a > 0.75 then local s = (a - 0.6) * 1.2 blend(x - 2, y, r, g, b, s); blend(x + 2, y, r, g, b, s) blend(x, y - 2, r, g, b, s); blend(x, y + 2, r, g, b, s) end end function render() built = false if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local t = frame * STEP_HZ // FPS draw_dollops(t) for i = 1, #BERRIES do local c = (t + i * 37) % 75 if c < 14 then star(BERRIES[i][1] + 1, BERRIES[i][2] + 2, c / 14, c3(GLINT)) end end local amp = 0.09 + 0.03 * sin(t * TAU / (13 * STEP_HZ)) local th = amp * sin(OM * t) local ax = AX + LEN * sin(th) local y1 = DY + DH for y = y1, AY - 1 do local s = (AY - (y + 0.5)) / (AY - y1) local x = AX + (ax - AX) * s - 0.5 local ix = floor(x) local f = x - ix blend(ix, y, STRING[1], STRING[2], STRING[3], 1 - f) blend(ix + 1, y, STRING[1], STRING[2], STRING[3], f) end local q = floor((ax - ATX) * NP + 0.5) local p = q % NP if not RAS[0] then RAS[0] = shift_x(0); built = true end if not RAS[p] and not built then RAS[p] = shift_x(p / NP); built = true end local R = RAS[p] if not R then R = RAS[0]; q = floor(ax - ATX + 0.5) * NP end gfx.blit_rgb(R, q // NP, DY, DW + 1, DH, KR, KG, KB) if SPARK then for k = 1, 4 do local per = 34 + k * 5 local c = (t + k * 11) % per local n = (t + k * 11) // per local h = hash32(n * 0x9E3779B1 + k * 0x85EBCA6B) star(3 + umod(h, 58), 3 + umod(h >> 8, 38), c / per, 255, k % 2 == 0 and 236 or 250, k % 2 == 0 and 190 or 250) end end end