info = { type = "image", title = "Rainy flower shop", category = "city", author = "BRRRO", version = "1.0", license = "MIT", desc = "Rain on the window of a glowing plant shop", api = 44, } local tr = ({ sk = { ["Running drops"] = "Stekajúce kvapky", ["Traffic"] = "Premávka", ["none"] = "žiadna", ["rare"] = "riedka", ["busy"] = "hustá" }, cs = { ["Running drops"] = "Stékající kapky", ["Traffic"] = "Provoz", ["none"] = "žádný", ["rare"] = "řídký", ["busy"] = "hustý" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "drops", label = T("Running drops"), type = "int", min = 2, max = 8, default = 6 }, { key = "traffic", label = T("Traffic"), type = "int", default = "rare", opts = { keys = { "none", "rare", "busy" }, T("none"), T("rare"), T("busy") } }, } local rect, px, blend_rect, blend = gfx.rect, gfx.px, gfx.blend_rect, gfx.blend local floor, sin, sqrt, max, min = math.floor, math.sin, math.sqrt, math.max, math.min local hash32, umod = math.hash32, math.umod local W, H = gfx.W, gfx.H local PI = 3.14159 local GX, GY, GW, GH = 3, 5, 58, 46 local function ell(cx, cy, rx, ry, c, a) for dy = -ry, ry do local k = 1 - (dy / (ry + 0.6)) ^ 2 local hw = floor(rx * sqrt(k > 0 and k or 0) + 0.5) blend_rect(cx - hw, cy + dy, 2 * hw + 1, 1, c[1], c[2], c[3], a) end end local function soft(cx, cy, rx, ry, c, a) ell(cx, cy, rx + 2, ry + 2, c, a * 0.22) ell(cx, cy, rx + 1, ry + 1, c, a * 0.35) ell(cx, cy, rx, ry, c, a * 0.85) end local GREEN1, GREEN2, GREEN3 = { 46, 112, 60 }, { 84, 152, 80 }, { 70, 136, 70 } local POT, PINK, YEL, WHITE = { 176, 92, 58 }, { 222, 100, 130 }, { 244, 206, 80 }, { 236, 236, 240 } local BG, M1, M2, stage = nil, nil, nil, 0 local function bake1() rect(0, 0, W, H, 20, 24, 34) for k = 0, 15 do rect(k * 4, 0, 4, 4, (k % 2 == 0) and 40 or 30, (k % 2 == 0) and 94 or 68, (k % 2 == 0) and 78 or 60) end rect(0, 4, W, 1, 12, 30, 28) for y = GY, GY + 32 do local t = (y - GY) / 32 rect(GX, y, GW, 1, floor(100 + 118 * t + 0.5), floor(58 + 96 * t + 0.5), floor(42 + 56 * t + 0.5)) end rect(GX, 38, GW, 13, 92, 58, 38) for x = GX + 9, GX + GW - 1, 12 do rect(x, 39, 1, 12, 70, 44, 30) end rect(GX, 38, GW, 1, 150, 98, 58) rect(GX, 36, GW, 2, 150, 96, 56) rect(GX, 21, GW, 1, 150, 96, 56) rect(GX, 22, GW, 1, 86, 54, 36) rect(0, 51, W, 3, 120, 80, 50) rect(0, 51, W, 1, 168, 118, 70) for k = 0, 9 do blend_rect(4, 54 + k, 56, 1, 230, 150, 80, 0.34 * (1 - k / 10)) end rect(21, GY, 2, 3, 40, 28, 24) soft(22, 11, 12, 8, { 255, 228, 170 }, 0.16) ell(22, 10, 5, 3, { 255, 240, 200 }, 0.8) BG = gfx.snapshot(0, 0, W, H) end local function bake2() gfx.blit_rgb(BG, 0, 0, W, H) soft(11, 14, 5, 4, GREEN3, 0.9); soft(10, 12, 3, 2, GREEN2, 0.9); ell(11, 19, 3, 2, POT, 0.85) soft(26, 17, 4, 3, GREEN1, 0.8); soft(26, 20, 2, 3, GREEN1, 0.5) soft(40, 14, 3, 3, PINK, 0.9); soft(38, 17, 4, 2, GREEN3, 0.85); ell(40, 19, 3, 2, POT, 0.85) soft(52, 14, 3, 6, GREEN2, 0.85); ell(52, 19, 3, 2, POT, 0.85) soft(14, 28, 9, 6, GREEN1, 0.95); soft(10, 26, 5, 4, GREEN2, 0.9); soft(18, 27, 5, 4, GREEN3, 0.9) rect(10, 32, 9, 4, POT[1], POT[2], POT[3]) soft(30, 28, 3, 7, { 72, 142, 86 }, 0.9); soft(27, 26, 2, 3, { 72, 142, 86 }, 0.8); soft(33, 30, 2, 3, { 72, 142, 86 }, 0.8) rect(27, 33, 7, 3, POT[1], POT[2], POT[3]) soft(44, 29, 8, 5, { 40, 104, 60 }, 0.95); soft(44, 27, 6, 3, GREEN2, 0.85) rect(40, 33, 9, 3, POT[1], POT[2], POT[3]) soft(55, 28, 4, 3, PINK, 0.95); soft(58, 30, 3, 2, YEL, 0.95); soft(53, 29, 3, 2, WHITE, 0.9) rect(53, 33, 7, 3, POT[1], POT[2], POT[3]) BG = gfx.snapshot(0, 0, W, H) end local function bake3() gfx.blit_rgb(BG, 0, 0, W, H) for _, b in ipairs({ { 8, PINK, YEL, WHITE }, { 28, { 150, 110, 200 }, WHITE, { 120, 200, 130 } }, { 46, { 240, 140, 60 }, { 250, 190, 80 }, { 210, 70, 70 } } }) do blend_rect(b[1], 43, 12, 8, 70, 80, 92, 0.9) soft(b[1] + 3, 41, 4, 3, b[2], 0.95); soft(b[1] + 8, 40, 4, 3, b[3], 0.95); soft(b[1] + 6, 43, 3, 2, b[4], 0.9) end for i = 1, 36 do local h = hash32(i * 0x9E3779B1 + 5) local x, y = GX + 1 + umod(h, GW - 4), GY + 1 + umod(h >> 8, GH - 5) if umod(h >> 16, 3) == 0 then blend_rect(x, y, 1, 1, 220, 236, 250, 0.5) else blend_rect(x, y, 2, 3, 200, 224, 240, 0.28) blend(x, y, 255, 255, 255, 0.7) blend(x + 1, y + 2, 24, 20, 24, 0.5) end end blend_rect(GX, GY, GW, GH, 150, 190, 215, 0.05) BG = gfx.snapshot(0, 0, W, H) end local function radial(R) local S, rows, row = 2 * R + 1, {}, {} for y = -R, R do for x = -R, R do local d = sqrt(x * x + y * y) / (R + 0.5) row[x + R + 1] = d >= 1 and 0 or floor(255 * (1 - d)) end rows[y + R + 1] = string.char(table.unpack(row, 1, S)) end return table.concat(rows), S end local NDROP, LANE = 6, { 900, 1300 } function on_settings() NDROP = cfg.drops or 6 local t = cfg.traffic LANE = t == "none" and {} or t == "busy" and { 420, 540, 700 } or { 900, 1300 } end local FADE = 300 local function drop(i) local per = 480 + (i * 97) % 170 local f = frame + i * 211 local cyc, tt = f // per, f % per local h = hash32(i * 7919 + cyc * 104729) local x, y0 = GX + 3 + umod(h, GW - 7), GY + 2 + umod(h >> 8, 14) local L, dur = 16 + umod(h >> 16, 18), 140 + umod(h >> 20, 120) local fade, y = 1, nil if tt < dur then local u = tt / dur y = y0 + L * (u - 0.85 * sin(6 * PI * u) / (6 * PI)) else y = y0 + L fade = 1 - (tt - dur) / FADE if fade <= 0 then return end end local yi = floor(y) if yi > y0 then blend_rect(x, y0, 1, yi - y0, 200, 226, 244, 0.20 * fade) blend_rect(x - 1, y0, 1, yi - y0, 20, 28, 40, 0.10 * fade) end blend_rect(x, yi, 2, 3, 205, 228, 242, 0.5 * fade) blend(x, yi, 255, 255, 255, 0.8 * fade) blend(x + 1, yi + 2, 24, 20, 24, 0.5 * fade) end local function car(k, per) local f = frame + k * 313 local cyc, tt = f // per, f % per local dur = 170 if tt >= dur then return end local u = tt / dur local dir = (hash32(k * 31 + cyc) & 1) == 0 and 1 or -1 local x = dir > 0 and (-16 + (W + 32) * u) or (W + 16 - (W + 32) * u) local env = sin(PI * u) ^ 0.7 local head = dir < 0 local r, g, b = 255, 246, 214 if not head then r, g, b = 255, 70, 50 end local y = 38 + (k % 2) * 4 blend_rect(GX, GY, GW, GH, r, g, b, 0.05 * env) for s = 0, 1 do local lx = floor(x) + s * 11 gfx.blend_mask(M2, r, g, b, lx - 14, y - 14, 29, 29, 29, 29, 0.32 * env) gfx.blend_mask(M1, r, g, b, lx - 6, y - 6, 13, 13, 13, 13, 0.9 * env) end end local RIP = { { 14, 59 }, { 38, 60 }, { 52, 58 } } function render() if stage < 4 then stage = stage + 1 if stage == 1 then bake1() elseif stage == 2 then bake2() elseif stage == 3 then bake3() else M1 = radial(6); M2 = radial(14) end if stage < 4 then gfx.ready(false) return end end gfx.blit_rgb(BG, 0, 0, W, H) gfx.clip(GX, GY, GW, GH) for i = 1, NDROP do drop(i) end for k = 1, #LANE do car(k, LANE[k]) end gfx.clip() local on = (hash32(frame // 4) % 29 == 0) and 0.15 or 1 blend_rect(40, 7, 20, 9, 255, 70, 140, 0.10 * on) gfx.text(42, 9, "OPEN", 255, 90, 160, { font = "3x5", alpha = 0.55 + 0.4 * on }) for i = 1, #RIP do local per = 46 + i * 9 local u = ((frame + i * 17) % per) / per local r = 1 + floor(7 * u) local ry = max(1, floor(r * 0.35)) local cx, cy = RIP[i][1], RIP[i][2] local a = 0.4 * (1 - u) blend_rect(cx - r, cy - ry, 2 * r + 1, 1, 190, 210, 230, a) blend_rect(cx - r, cy + ry, 2 * r + 1, 1, 190, 210, 230, a) blend_rect(cx - r, cy - ry + 1, 1, 2 * ry - 1, 190, 210, 230, a) blend_rect(cx + r, cy - ry + 1, 1, 2 * ry - 1, 190, 210, 230, a) end for i = 1, 3 do local per = 60 + i * 23 local f = frame + i * 41 local u = (f % per) / per local x = 8 + umod(hash32(i * 977 + f // per), 48) local y = 5 + floor(46 * u * u) blend(x, y, 215, 232, 255, 0.7) blend_rect(x, y - 2, 1, 2, 215, 232, 255, 0.3) end end