info = { type = "image", title = "Rain sneakers", category = "other", author = "BRRRO", version = "1.0", license = "MIT", desc = "Sneakers splash through rainy puddles", api = 33, } local tr = ({ sk = { ["Sneaker colour"] = "Farba tenisiek" }, cs = { ["Sneaker colour"] = "Barva tenisek" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "shoe", label = T("Sneaker colour"), type = "color", default = "#FF6A3D" }, } local rect, blend, blend_rect, blit = gfx.rect, gfx.blend, gfx.blend_rect, gfx.blit_indexed local floor, sin, cos, sqrt, abs = math.floor, math.sin, math.cos, math.sqrt, math.abs local hash32, umod = math.hash32, math.umod local W, H = gfx.W, gfx.H local TAU = 6.28318 local TH = 18 local DELTA = 8 local VG = DELTA / TH local Y0, YB = 22, 14 local SL = 22 local M = 9 local SLAB = { { 30, 32, 76 }, { 35, 37, 86 } } local JOINT = { 14, 15, 40 } local JEAN, JEAN_L, JEAN_D, CUFF = { 40, 72, 176 }, { 58, 94, 206 }, { 28, 50, 132 }, { 72, 108, 216 } local PUD_T, PUD_B, PUD_R = { 60, 80, 156 }, { 36, 46, 106 }, { 88, 110, 184 } local SPRZ = { [[ 00011111177000 00166666666700 00166666666700 00166666666700 01442222223370 01442222223370 01442222223370 01442222223370 01455555555370 01442222223370 01455555555370 01442222223370 14455555555337 14442222223337 14455555555337 01442222223370 01442222223370 01442222223370 01442222223370 01442222223370 01111111111170 00111111111700 00111111117700 00001111170000]], [[ 00077111111000 00766666666100 00766666666100 00766666666100 07332222224410 07332222224410 07332222224410 07332222224410 07355555555410 07332222224410 07355555555410 07332222224410 73355555555441 73332222224441 73355555555441 07332222224410 07332222224410 07332222224410 07332222224410 07332222224410 07111111111110 00711111111100 00771111111100 00007111110000]], [[ 000111111177000 001666666666700 001666666666700 001666666666700 001442222233700 014442222233370 014442222233370 014442222233370 014555555555370 014442222233370 014555555555370 014442222233370 014555555555370 144442222233337 144555555555337 144442222233337 014442222233370 014442222233370 014442222233370 014442222233370 014442222233370 011111111111170 001111111111700 001111111111700 000111111117000 000011111170000]], [[ 000771111111000 007666666666100 007666666666100 007666666666100 007332222244100 073332222244410 073332222244410 073332222244410 073555555555410 073332222244410 073555555555410 073332222244410 073555555555410 733332222244441 733555555555441 733332222244441 073332222244410 073332222244410 073332222244410 073332222244410 073332222244410 071111111111110 007111111111100 007111111111100 000711111111000 000071111110000]], [[ 0000111111770000 0001666666667000 0016666666666700 0016666666666700 0014422222233700 0014422222233700 0144422222233370 0144422222233370 0145555555555370 0144422222233370 0145555555555370 0144422222233370 0145555555555370 0144422222233370 1445555555555337 1444422222233337 1445555555555337 1444422222233337 0144422222233370 0144422222233370 0144422222233370 0144422222233370 0144422222233370 0111111111111170 0011111111111700 0011111111111700 0001111111117000 0000111111770000]], [[ 0000771111110000 0007666666661000 0076666666666100 0076666666666100 0073322222244100 0073322222244100 0733322222244410 0733322222244410 0735555555555410 0733322222244410 0735555555555410 0733322222244410 0735555555555410 0733322222244410 7335555555555441 7333322222244441 7335555555555441 7333322222244441 0733322222244410 0733322222244410 0733322222244410 0733322222244410 0733322222244410 0711111111111110 0071111111111100 0071111111111100 0007111111111000 0000771111110000]], } local FW, FH = { 14, 15, 16 }, { 24, 26, 28 } local UNZ = { ["\n"] = "" } for i = 0, 9 do UNZ[string.char(48 + i)] = string.char(i) end local function unz(s) return (s:gsub(".", UNZ)) end local SPR = setmetatable({}, { __index = function(t, k) local v = { unz(SPRZ[2 * k - 1]), unz(SPRZ[2 * k]) } t[k] = v return v end }) local PAL = {} function on_settings() local c = cfg.shoe or { r = 255, g = 106, b = 61 } local function lerp(a, b, t) return floor(a + (b - a) * t + 0.5) end PAL = { 0, 0, 0, 226, 226, 238, c.r, c.g, c.b, floor(c.r * 0.62), floor(c.g * 0.62), floor(c.b * 0.62), lerp(c.r, 255, 0.35), lerp(c.g, 255, 0.35), lerp(c.b, 255, 0.35), 240, 240, 250, 18, 14, 34, 150, 152, 178 } end local RINGZ = { [[ 111 101 111]], [[ 01110 10001 01110]], [[ 0011100 1100011 1000001 1100011 0011100]], [[ 001111100 110000011 100000001 110000011 001111100]], [[ 00011111000 01100000110 10000000001 10000000001 10000000001 01100000110 00011111000]], [[ 0000111110000 0010000000100 0100000000010 1000000000001 1000000000001 1000000000001 0100000000010 0010000000100 0000111110000]], [[ 000001111100000 001100000001100 010000000000010 100000000000001 100000000000001 100000000000001 010000000000010 001100000001100 000001111100000]], [[ 00000111111100000 00011000000011000 01100000000000110 01000000000000010 10000000000000001 10000000000000001 10000000000000001 01000000000000010 01100000000000110 00011000000011000 00000111111100000]], } local RING = setmetatable({}, { __index = function(t, r) local v = unz(RINGZ[r]); t[r] = v; return v end }) local RW, RH = {}, {} for r = 1, 8 do RW[r], RH[r] = 2 * r + 1, 2 * math.max(1, floor(r * 0.6 + 0.5)) + 1 end local RPAL = {} for a = 1, 4 do local k = (a - 1) / 3 RPAL[a] = { 0, 0, 0, floor(168 - 80 * k), floor(194 - 84 * k), floor(250 - 70 * k) } end local function ring(r, cx, cy, a) if r < 1 then return end if r > 8 then r = 8 end blit(RING[r], RPAL[a], cx - r, cy - (RH[r] - 1) // 2, RW[r], RH[r], RW[r], RH[r], true) end local function hline(yc, tk, c) local top, bot = yc - tk / 2, yc + tk / 2 for i = floor(top), floor(bot - 0.001) do local a = math.min(bot, i + 1) - math.max(top, i) if a > 0.03 then blend_rect(0, i, W, 1, c[1], c[2], c[3], a) end end end local function pavement(S) local r0 = floor(S / SL) for r = r0, r0 + 3 do local y0 = r * SL - S if y0 < H then local iy0, iy1 = floor(y0 + 0.5), floor(y0 + SL + 0.5) local c = SLAB[(hash32(r * 0x9E3779B1) & 1) + 1] rect(0, iy0, W, iy1 - iy0, c[1], c[2], c[3]) local xs = (r % 2 == 0) and { 22, 44 } or { 11, 33, 55 } for i = 1, #xs do rect(xs[i], iy0, 1, iy1 - iy0, JOINT[1], JOINT[2], JOINT[3]) end hline(y0, 1.5, JOINT) end end end local function puddle(cx, cy, rx, ry, ph) for y = floor(cy - ry), floor(cy + ry) do local d = (y + 0.5 - cy) / ry if d > -1 and d < 1 then local hw = floor(rx * sqrt(1 - d * d) * (1 + 0.1 * sin(d * 5 + ph)) + 0.5) if hw >= 1 then local t = (d + 1) / 2 rect(cx - hw, y, 2 * hw, 1, PUD_R[1], PUD_R[2], PUD_R[3]) if hw >= 3 and abs(d) < 0.8 then rect(cx - hw + 1, y, 2 * hw - 2, 1, floor(PUD_T[1] + (PUD_B[1] - PUD_T[1]) * t + 0.5), floor(PUD_T[2] + (PUD_B[2] - PUD_T[2]) * t + 0.5), floor(PUD_T[3] + (PUD_B[3] - PUD_T[3]) * t + 0.5)) end end end end end local FX = { 16, 48 } local function puddles_and_splash(frame, after) local fn = frame / TH for j = floor((fn - 11) / M), floor(fn / M) + 1 do local n = M * j + 5 local cy = 40 + DELTA * (n - fn) if cy > -12 and cy < 76 then local h = hash32(j * 0x85EBCA6B) local f = n % 2 local rx, ry = 13 + umod(h, 4), 8 + umod(h >> 4, 3) local cx = FX[f + 1] + umod(h >> 8, 5) - 2 if not after then puddle(cx, floor(cy + 0.5), rx, ry, umod(h >> 12, 628) / 100) for s = 0, 1 do local P = 22 + s * 9 local q = frame + umod(h >> (16 + s * 4), P) local k, a = floor(q / P), q % P if a < 16 then local hh = hash32(j * 131 + s * 17 + k * 7919) local dx = umod(hh, floor(rx * 0.9)) - floor(rx * 0.45) local dy = umod(hh >> 8, floor(ry * 0.5)) - floor(ry * 0.25) ring(1 + a // 3, cx + dx, floor(cy + 0.5) + dy, 1 + a // 5) end end local sa = frame - n * TH if sa >= 0 and sa < 26 then ring(2 + sa // 4, FX[f + 1], floor(cy - 3 - sa * 0 + 0.5), 1 + sa // 7) end else local sa = frame - n * TH if sa >= 0 and sa < 20 then local fx, fy = FX[f + 1], 44 - sa * VG local life = 1 - sa / 20 for i = 1, 8 do local th = i / 8 * TAU + 0.4 + (i % 2) * 0.3 local rr = (2 + 8 * (1 - (1 - sa / 20) ^ 2)) * (0.7 + (i % 3) * 0.2) local lift = 5 * sin(3.14159 * sa / 20) * (0.5 + (i % 2) * 0.5) blend(floor(fx + cos(th) * rr + 0.5), floor(fy + sin(th) * rr * 0.6 - lift + 0.5), 190, 212, 255, 0.4 + 0.6 * life) end end end end end end local function ease(u) if u <= 0 then return 0 elseif u >= 1 then return 1 end return u * u * (3 - 2 * u) end local function foot(f, frame) local ph = (frame / TH + f) % 2 local y, k if ph < 1 then y, k = floor(Y0 - DELTA * ph + 0.5), 1 else local s = ph - 1 y = floor(YB + DELTA * ease((s - 0.08) / 0.84) + 0.5) k = (s < 0.18 or s > 0.84) and 2 or 3 end local w, h = FW[k], FH[k] local x0 = 16 - w // 2 if f == 1 then x0 = W - x0 - w end blit(SPR[k][f + 1], PAL, x0, y, w, h, w, h, true) local ye, lx, lw = y + 5, x0 + 1, w - 2 rect(lx, -1, lw, ye + 1, JEAN[1], JEAN[2], JEAN[3]) rect(lx, -1, 2, ye + 1, JEAN_L[1], JEAN_L[2], JEAN_L[3]) rect(lx + lw - 3, -1, 3, ye + 1, JEAN_D[1], JEAN_D[2], JEAN_D[3]) rect(lx + lw // 2, 8, 1, ye - 12, JEAN_D[1], JEAN_D[2], JEAN_D[3]) rect(lx, ye - 2, lw, 2, CUFF[1], CUFF[2], CUFF[3]) rect(lx, ye, lw, 1, JEAN_D[1] - 8, JEAN_D[2] - 12, JEAN_D[3] - 40) end local function rain(frame) for i = 1, 9 do local h = hash32(i * 0xC2B2AE35) local y = (frame * 3 + umod(h >> 8, 90)) % 90 - 14 blend_rect(umod(h, W), y, 1, 4, 150, 172, 236, 0.28) end for i = 1, 12 do local P = 14 + umod(hash32(i * 977), 7) local q = frame + umod(hash32(i * 131), P) local k, a = floor(q / P), q % P if a < 6 then local h = hash32(i * 7919 + k * 0x9E3779B1) local x, y = umod(h, W), 34 + umod(h >> 8, 30) if a < 2 then blend(x, y, 170, 190, 250, 0.7 - a * 0.25) elseif a < 5 then ring(2, x, y, a) end end end end function render() local S = frame * VG pavement(S) puddles_and_splash(frame, false) foot(0, frame); foot(1, frame) puddles_and_splash(frame, true) rain(frame) end