info = { type = "image", title = "Rainy grave walk", category = "holidays", author = "BRRRO", version = "1.0", license = "MIT", desc = "Skeleton with an umbrella lays a flower", api = 33, } local tr = ({ sk = { ["Rain"] = "Dážď", ["Lightning"] = "Blesk" }, cs = { ["Rain"] = "Déšť", ["Lightning"] = "Blesk" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "rain", label = T("Rain"), type = "int", min = 1, max = 5, default = 3 }, { key = "flash", label = T("Lightning"), type = "bool", default = true }, } local rect, px, blend_rect, blit_indexed = gfx.rect, gfx.px, gfx.blend_rect, gfx.blit_indexed local blit_rgb, snapshot = gfx.blit_rgb, gfx.snapshot local floor, sin = math.floor, math.sin local hash32, umod = math.hash32, math.umod local W, H = gfx.W, gfx.H local PN = { sky = { { 10, 12, 32 }, { 18, 18, 48 }, { 30, 24, 64 }, { 46, 32, 76 }, { 64, 40, 84 } }, cloud = { 36, 34, 70 }, hill = { 20, 22, 44 }, fence = { 44, 46, 78 }, g1 = { 24, 58, 48 }, g2 = { 30, 76, 58 }, p1 = { 74, 72, 104 }, p2 = { 62, 60, 90 }, pjoint = { 48, 46, 76 }, puddle = { 96, 108, 160 }, stone = { 84, 88, 124 }, hi = { 130, 136, 176 }, sh = { 52, 54, 84 }, } local PL = { sky = { { 70, 76, 120 }, { 86, 90, 140 }, { 100, 104, 160 }, { 120, 124, 176 }, { 140, 142, 190 } }, cloud = { 116, 120, 170 }, hill = { 56, 60, 100 }, fence = { 150, 156, 200 }, g1 = { 60, 110, 96 }, g2 = { 78, 130, 110 }, p1 = { 140, 140, 176 }, p2 = { 120, 120, 160 }, pjoint = { 96, 96, 140 }, puddle = { 190, 200, 240 }, stone = { 180, 186, 226 }, hi = { 230, 236, 255 }, sh = { 120, 124, 164 }, } local function c3(c) return c[1], c[2], c[3] end local function checker(w, h, ph) local a, b = ("\1\2"):rep(w // 2), ("\2\1"):rep(w // 2) local rows = {} for y = 0, h - 1 do rows[y + 1] = ((y + ph) % 2 == 0) and a or b end return table.concat(rows) end local CHK_G, CHK_P = checker(W, 14, 0), checker(W, 10, 1) local function stone(P, x, yb, w, h, cross) for k = 0, h - 1 do local inset = k == 0 and 2 or k == 1 and 1 or 0 rect(x + inset, yb - h + k, w - 2 * inset, 1, c3(P.stone)) end rect(x, yb - h + 2, 1, h - 2, c3(P.hi)) rect(x + w - 1, yb - h + 2, 1, h - 2, c3(P.sh)) rect(x, yb - 1, w, 1, c3(P.sh)) if cross then rect(x + w // 2, yb - h + 4, 1, 8, c3(P.sh)); rect(x + w // 2 - 2, yb - h + 6, 5, 1, c3(P.sh)) end end local function cross(P, x, yb, h) rect(x, yb - h, 1, h, c3(P.stone)); rect(x - 2, yb - h + 2, 5, 1, c3(P.stone)) px(x - 1, yb - h, c3(P.hi)); px(x - 2, yb - h + 2, c3(P.hi)) end local function scene(P) local S = P.sky local edges = { 0, 10, 18, 25, 30, 36 } for i = 1, 5 do rect(0, edges[i], W, edges[i + 1] - edges[i], c3(S[i])) end for i = 1, 4 do local y = edges[i + 1] for x = 0, W - 1, 2 do px(x, y, c3(S[i + 1])); px(x + 1, y + 1, c3(S[i])) end end for _, c in ipairs({ { 4, 6, 22, 5 }, { 30, 12, 26, 4 }, { 46, 4, 20, 5 } }) do rect(c[1] + 3, c[2], c[3] - 6, 1, c3(P.cloud)); rect(c[1], c[2] + 1, c[3], c[4] - 1, c3(P.cloud)) rect(c[1] + 5, c[2] + c[4], c[3] - 10, 1, c3(P.cloud)) end for x = 0, W - 1 do local hy = floor(30 + 3 * sin(x * 0.13) + 2 * sin(x * 0.31 + 1) + 0.5) rect(x, hy, 1, 40 - hy, c3(P.hill)) end for _, tx in ipairs({ 8, 30, 58 }) do rect(tx, 18, 1, 14, c3(P.hill)) for k = 1, 4 do px(tx - k, 22 - k, c3(P.hill)); px(tx + k, 25 - k, c3(P.hill)) end px(tx - 5, 17, c3(P.hill)); px(tx + 5, 20, c3(P.hill)) end rect(0, 37, W, 1, c3(P.fence)); rect(0, 41, W, 1, c3(P.fence)) for x = 1, W - 1, 3 do rect(x, 35, 1, 8, c3(P.fence)); px(x, 34, c3(P.fence)) end blit_indexed(CHK_G, { 0, 0, 0, P.g1[1], P.g1[2], P.g1[3], P.g2[1], P.g2[2], P.g2[3] }, 0, 40, W, 14, W, 14, true) blit_indexed(CHK_P, { 0, 0, 0, P.p1[1], P.p1[2], P.p1[3], P.p2[1], P.p2[2], P.p2[3] }, 0, 54, W, 10, W, 10, true) rect(0, 57, W, 1, c3(P.pjoint)); rect(0, 61, W, 1, c3(P.pjoint)) rect(5, 59, 7, 2, c3(P.puddle)); rect(26, 56, 6, 1, c3(P.puddle)); rect(54, 60, 8, 2, c3(P.puddle)) cross(P, 6, 49, 10); cross(P, 19, 46, 7); stone(P, 25, 50, 6, 9); cross(P, 61, 50, 8) stone(P, 44, 56, 13, 21, true) end local BG, BGL local STAGES = { function() scene(PN); BG = snapshot(0, 0, W, H) end, function() scene(PL); BGL = snapshot(0, 0, W, H) end } local STAGE = 1 local NMAX = 82 local DX, DV, DL, DO = {}, {}, {}, {} for i = 1, NMAX do local h = hash32(i * 0x9E3779B1) DX[i] = umod(h, W) DV[i] = 2 + umod(h >> 6, 10) / 10 DL[i] = 46 + umod(h >> 10, 17) DO[i] = umod(h >> 16, 90) end local function rain(n, u0, u1, uy) for i = 1, n do local x, v, land = DX[i], DV[i], DL[i] local fall = (land + 4) / v local pos = (frame + DO[i]) % (fall + 3) if pos < fall then local y = floor(v * pos) - 4 if not (x >= u0 and x <= u1 and y + 1 >= uy) then if i % 2 == 0 then rect(x, y, 1, 2, 110, 170, 230) else rect(x, y, 1, 2, 62, 102, 172) end end else px(x - 1, land, 62, 102, 172); px(x + 1, land, 62, 102, 172) end end end local BONE, DARK = { 226, 222, 204 }, { 22, 18, 36 } local UMB, UMB_D, UMB_L = { 180, 40, 72 }, { 112, 22, 52 }, { 224, 88, 110 } local SWING = { 0, 2, 0, -2 } local STG = { { d = 0, lean = 0, hx = 4, hy = 9 }, { d = 1, lean = 1, hx = 6, hy = 11 }, { d = 2, lean = 2, hx = 7, hy = 12 } } local function flower(hx, hy, a) if a >= 1 then rect(hx, hy - 1, 1, 4, 60, 150, 70); rect(hx - 1, hy - 4, 3, 3, 214, 40, 66); px(hx, hy - 3, 240, 210, 60) else blend_rect(hx, hy - 1, 1, 4, 60, 150, 70, a); blend_rect(hx - 1, hy - 4, 3, 3, 214, 40, 66, a) blend_rect(hx, hy - 3, 1, 1, 240, 210, 60, a) end end local function leg(x, yh, sw) local n = 62 - yh local h1 = (n + 1) // 2 rect(x, yh, 1, h1, c3(BONE)) if sw ~= 0 then rect(x + (sw > 0 and 1 or -1), yh + h1 - 1, 1, 1, c3(BONE)) end rect(x + sw, yh + h1, 1, n - h1, c3(BONE)) px(x + sw + 1, 61, c3(BONE)) end local function limb(x0, y0, x1, y1) local n = math.max(math.abs(x1 - x0), math.abs(y1 - y0)) for k = 0, n do px(floor(x0 + (x1 - x0) * k / n + 0.5), floor(y0 + (y1 - y0) * k / n + 0.5), c3(BONE)) end end local function skeleton(cx, st, phase, holding) local S = STG[st + 1] local ux, y0 = cx + S.lean, 43 + S.d local pc = cx + S.lean // 2 local xc = ux - 4 blend_rect(cx - 4, 62, 9, 1, 0, 0, 0, 0.35) rect(xc, y0 - 4, 1, 11, 200, 160, 90) rect(xc - 4, y0 - 8, 9, 1, c3(UMB)); rect(xc - 6, y0 - 7, 13, 1, c3(UMB)); rect(xc - 8, y0 - 6, 17, 1, c3(UMB)) rect(xc - 8, y0 - 5, 17, 1, c3(UMB_D)) for k = 0, 8 do px(xc - 8 + 2 * k, y0 - 4, c3(UMB_D)) end px(xc - 5, y0 - 7, c3(UMB_L)); px(xc - 3, y0 - 8, c3(UMB_L)) rect(ux - 2, y0, 5, 4, c3(BONE)); rect(ux - 1, y0 + 4, 3, 1, c3(BONE)) rect(ux - 1, y0 + 1, 1, 2, c3(DARK)); rect(ux + 1, y0 + 1, 1, 2, c3(DARK)) px(ux - 1, y0 + 4, c3(DARK)); px(ux + 1, y0 + 4, c3(DARK)) rect(ux, y0 + 5, 1, 3, c3(BONE)); rect(pc, y0 + 8, 1, 4, c3(BONE)) rect(ux - 2, y0 + 6, 5, 1, c3(BONE)); rect(ux - 2, y0 + 8, 5, 1, c3(BONE)); rect(pc - 2, y0 + 10, 5, 1, c3(BONE)) rect(pc - 2, y0 + 12, 5, 2, c3(BONE)) local yh, sw = y0 + 14, 0 if st == 0 then sw = SWING[phase + 1] leg(pc - 1, yh, -sw); leg(pc + 1, yh, sw) else leg(pc - 1, yh, -S.d); leg(pc + 1, yh, S.d) end px(ux - 2, y0 + 6, c3(BONE)); px(ux - 3, y0 + 7, c3(BONE)); px(xc, y0 + 7, c3(BONE)) local hx, hy = ux + S.hx, y0 + S.hy limb(ux + 2, y0 + 6, hx, hy) if holding then flower(hx, hy, 1) end end local CYC = 330 local STOP = 38 local function timeline(t) if t < 104 then return -14 + t // 2, 0, ((-14 + t // 2) // 3) % 4, true end if t < 116 then return STOP, 0, 0, true end if t < 128 then return STOP, 1, 0, true end if t < 140 then return STOP, 2, 0, true end if t < 160 then return STOP, 2, 0, false end if t < 170 then return STOP, 1, 0, false end if t < 195 then return STOP, 0, 0, false end local cx = STOP + (t - 195) // 2 return cx, 0, (cx // 3) % 4, false end function render() if STAGE <= #STAGES then STAGES[STAGE](); STAGE = STAGE + 1 return end local k = frame % 250 - 120 local lit = cfg.flash ~= false and ((k >= 0 and k < 2) or (k >= 4 and k < 6)) blit_rgb(lit and BGL or BG, 0, 0, W, H) if cfg.flash ~= false and k >= 0 and k < 3 then local x = 10 + umod(hash32((frame // 250) * 0x85EBCA6B), 44) for y = 0, 33, 3 do x = x + umod(hash32(y * 31 + frame // 250), 5) - 2 rect(x, y, 1, 3, 255, 250, 210) end end local t = frame % CYC if t >= 140 then flower(47, 57, t >= 300 and (CYC - t) / 30 or 1) end local cx, st, phase, holding = timeline(t) local u0, u1, uy = 1000, 1000, 0 if cx > -12 and cx < 76 then local S = STG[st + 1] local xc = cx + S.lean - 4 u0, u1, uy = xc - 8, xc + 8, 35 + S.d end rain(12 + 14 * (cfg.rain or 3), u0, u1, uy) if u0 < 1000 then skeleton(cx, st, phase, holding) end end