info = { type = "image", title = "Puddle jump", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "A raincoat kid splashes in a night puddle", api = 33, } local tr = ({ sk = { ["Raincoat"] = "Pršiplášť", ["Rain"] = "Dážď" }, cs = { ["Raincoat"] = "Pláštěnka", ["Rain"] = "Déšť" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "coat", label = T("Raincoat"), type = "color", default = "#FFCE3C" }, { key = "rain", label = T("Rain"), type = "int", min = 1, max = 8, default = 4 }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, sin, sqrt = math.floor, math.sin, math.sqrt local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local SKY_T, SKY_B = { 22, 26, 66 }, { 48, 54, 104 } local BLD = { 14, 16, 44 } local CURB, ROAD = { 74, 76, 122 }, { 34, 36, 66 } local POLE = { 16, 16, 40 } local PUD_T, PUD_B = { 82, 96, 160 }, { 52, 60, 118 } local SKIN, DARK = { 240, 184, 152 }, { 36, 24, 40 } local BOOT = { 206, 54, 76 } local PCX, PCY, PRX, PRY = 28, 56, 22, 5 local FX, FY = 28, 57 local PERIOD = 42 local function c3(c) return c[1], c[2], c[3] end local function lerp3(a, b, k) return floor(a[1] + (b[1] - a[1]) * k + 0.5), floor(a[2] + (b[2] - a[2]) * k + 0.5), floor(a[3] + (b[3] - a[3]) * k + 0.5) end local BG = nil local function build_bg() for y = 0, 43 do rect(0, y, W, 1, lerp3(SKY_T, SKY_B, y / 43)) end local B = { { 0, 12, 27 }, { 12, 9, 18 }, { 21, 13, 31 }, { 34, 10, 22 }, { 44, 9, 29 }, { 53, 11, 20 } } for i = 1, #B do local b = B[i] rect(b[1], b[3], b[2], 44 - b[3], c3(BLD)) for wy = b[3] + 3, 40, 4 do for wx = b[1] + 2, b[1] + b[2] - 3, 4 do local h = umod(hash32(wx * 0x9E3779B1 + wy * 0x85EBCA6B), 7) if h == 0 then rect(wx, wy, 2, 2, 255, 206, 100) elseif h == 1 then rect(wx, wy, 2, 2, 140, 180, 250) end end end end rect(0, 44, W, 2, c3(CURB)) rect(0, 46, W, H - 46, c3(ROAD)) rect(58, 22, 2, 23, c3(POLE)) rect(49, 20, 11, 2, c3(POLE)) rect(48, 22, 6, 1, c3(POLE)) rect(49, 23, 4, 1, 255, 240, 170) for y = 24, 43 do local hw = 3 + (y - 24) * 0.5 local cx = 51 blend_rect(floor(cx - hw), y, floor(2 * hw), 1, 255, 214, 120, 0.07) blend_rect(floor(cx - hw * 0.66), y, floor(1.32 * hw), 1, 255, 214, 120, 0.07) blend_rect(floor(cx - hw * 0.33), y, floor(0.66 * hw), 1, 255, 220, 140, 0.08) end blend_rect(46, 22, 10, 3, 255, 226, 150, 0.22) for k = -3, 3 do local hw = floor(15 * sqrt(1 - (k / 3.6) ^ 2) + 0.5) blend_rect(57 - hw, 53 + k, 2 * hw, 1, 255, 214, 120, 0.07) blend_rect(57 - hw * 2 // 3, 53 + k, hw * 4 // 3, 1, 255, 214, 120, 0.07) end for k = -PRY, PRY do local hw = floor(PRX * sqrt(1 - (k / (PRY + 0.6)) ^ 2) + 0.5) rect(PCX - hw, PCY + k, 2 * hw, 1, lerp3(PUD_T, PUD_B, (k + PRY) / (2 * PRY))) end for k = 0, 3 do rect(43, 53 + k * 2, 2, 1, 255, 220, 130) end BG = gfx.snapshot(0, 0, W, H) end local CR, CG, CB = 255, 206, 60 local DR, DG, DB = 158, 128, 38 local HR, HG, HB = 255, 236, 140 local function draw_fig(lift, sq, arms, mouth) local x = FX local by = FY - lift rect(x - 4, by - 2, 3, 3, c3(BOOT)); rect(x + 2, by - 2, 3, 3, c3(BOOT)) local n = 12 - sq local top = by - 3 - n + 1 for r = 0, n - 1 do local w = r < 3 and 9 or 11 local y = top + r rect(x - w // 2, y, w, 1, CR, CG, CB) rect(x - w // 2, y, 2, 1, DR, DG, DB) rect(x + w // 2 - 1, y, 2, 1, HR, HG, HB) end if not arms then rect(x - 3, top + 4, 1, n - 6, DR, DG, DB) rect(x + 3, top + 4, 1, n - 6, DR, DG, DB) else rect(x - 8, top - 2, 3, 5, CR, CG, CB); rect(x - 8, top - 3, 3, 1, c3(SKIN)) rect(x + 6, top - 2, 3, 5, HR, HG, HB); rect(x + 6, top - 3, 3, 1, c3(SKIN)) px(x - 5, top + 2, DR, DG, DB); px(x + 5, top + 2, DR, DG, DB) end local hy = top - 8 local HW = { 5, 7, 9, 9, 9, 9, 9, 9 } for r = 1, 8 do local w = HW[r] rect(x - w // 2, hy + r - 1, w, 1, CR, CG, CB) rect(x - w // 2, hy + r - 1, 2, 1, DR, DG, DB) rect(x + w // 2 - 1, hy + r - 1, 2, 1, HR, HG, HB) end rect(x - 3, hy + 2, 7, 6, DR, DG, DB) rect(x - 2, hy + 3, 5, 5, c3(SKIN)) px(x - 1, hy + 5, c3(DARK)); px(x + 1, hy + 5, c3(DARK)) if mouth then rect(x - 1, hy + 7, 3, 1, 200, 70, 80) else px(x, hy + 7, 200, 90, 90) end end local RR, RG, RB = 196, 212, 255 local function ring(cx, cy, r, a) local ry = floor(r * 0.28 + 0.5) if ry < 1 then ry = 1 end local rf = ry + 0.5 for k = -ry, ry do local ak = k < 0 and -k or k local oa = ak - 0.5 if oa < 0 then oa = 0 end local o = floor(r * sqrt(1 - (oa / rf) ^ 2)) if ak == ry then blend_rect(cx - o, cy + k, 2 * o + 1, 1, RR, RG, RB, a) else local i = floor(r * sqrt(1 - ((ak + 0.5) / rf) ^ 2)) if i < 1 then i = 1 end blend_rect(cx - o, cy + k, o - i + 1, 1, RR, RG, RB, a) blend_rect(cx + i, cy + k, o - i + 1, 1, RR, RG, RB, a) end end end local DVX = { -1.9, -1.35, -0.8, -0.3, 0.3, 0.85, 1.4, 1.95 } local DVY = { -1.5, -2.1, -2.5, -2.9, -2.8, -2.4, -1.9, -1.4 } local RX, RV, RO = {}, {}, {} for i = 1, 80 do local h = hash32(i * 0xC2B2AE35) RX[i], RV[i], RO[i] = umod(h, W), 2.2 + umod(h >> 8, 13) / 10.0, umod(h >> 16, 800) / 10.0 end local N_RAIN = 40 function on_settings() local c = cfg.coat or { r = 255, g = 206, b = 60 } CR, CG, CB = c.r, c.g, c.b DR, DG, DB = floor(c.r * 0.62), floor(c.g * 0.62), floor(c.b * 0.62) HR, HG, HB = math.min(255, (c.r + 255) // 2 + 20), math.min(255, (c.g + 255) // 2 + 20), math.min(255, (c.b + 255) // 2 + 20) N_RAIN = (cfg.rain or 4) * 10 end function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local t = frame * STEP_HZ // FPS for k = 1, 5 do local q = t + k * 5 local a, pass = q % 24, q // 24 if a < 10 then local h = hash32(pass * 0x9E3779B1 + k * 0x85EBCA6B) ring(14 + umod(h, 30), 53 + umod(h >> 8, 7), 1 + floor(a * 0.45), 0.55 * (1 - a / 10)) end end local ph = (t + 12) % PERIOD local lift, sq, arms, mouth = 0, 0, false, false if ph < 4 then sq = ph == 1 and 2 or (ph == 2 and 2 or 1) elseif ph < 24 then local u = (ph - 4) / 20 lift = floor(9 * (1 - (2 * u - 1) ^ 2) + 0.5) arms, mouth = true, true elseif ph < 27 then sq = ph == 26 and 1 or 2; mouth = true end local age = (ph - 24) % PERIOD for k = 0, 2 do local a = age - k * 6 if a >= 0 and a < 26 then ring(FX, PCY, 2 + floor(a * 0.72), 0.85 * (1 - a / 26)) end end local ry = FY + 1 + lift * 6 // 10 if ry > 59 then ry = 59 end blend_rect(FX - 4, ry, 9, 2, CR, CG, CB, 0.22) blend_rect(FX - 3, ry + 2, 7, 1, CR, CG, CB, 0.14) draw_fig(lift, sq, arms, mouth) if lift == 0 then blend_rect(FX - 5, FY, 11, 1, 70, 82, 140, 0.55) end if age < 15 then for i = 1, 8 do local dx = FX + DVX[i] * age * 1.15 local dy = FY - 2 + DVY[i] * age + 0.11 * age * age if dy < FY + 1 then gfx.blend(floor(dx + 0.5), floor(dy + 0.5), 210, 228, 255, 0.95 * (1 - age / 16)) end end end for i = 1, N_RAIN do local p = (RO[i] + t * RV[i]) % 80 local y = floor(p) - 8 local x = (RX[i] + floor(p * 0.5)) % W px(x, y, 150, 168, 232) px((x - 1) % W, y - 2, 84, 98, 166) end end