info = { type = "image", title = "Bus stop rain", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "A girl boards the bus in the rain", api = 33, } local tr = ({ sk = { ["Rain"] = "Dážď", ["Coat"] = "Kabátik", ["Red"] = "Červený", ["Yellow"] = "Žltý", ["Blue"] = "Modrý", ["Bus"] = "Autobus", ["Orange"] = "Oranžový", ["Green"] = "Zelený" }, cs = { ["Rain"] = "Déšť", ["Coat"] = "Kabátek", ["Red"] = "Červený", ["Yellow"] = "Žlutý", ["Blue"] = "Modrý", ["Bus"] = "Autobus", ["Orange"] = "Oranžový", ["Green"] = "Zelený" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "rain", label = T("Rain"), type = "int", min = 0, max = 5, default = 3 }, { key = "coat", label = T("Coat"), type = "int", default = "red", opts = { keys = { "red", "yellow", "blue" }, T("Red"), T("Yellow"), T("Blue") } }, { key = "bus", label = T("Bus"), type = "int", default = "orange", opts = { keys = { "orange", "green" }, T("Orange"), T("Green") } }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, sqrt, max, min = math.floor, math.sqrt, math.max, math.min local hash32 = math.hash32 local W, H, FPS = gfx.W, gfx.H, gfx.FPS local T0 = 0 local CY = 26 local XS = 2 local COATS = { red = { { 176, 38, 48 }, { 222, 80, 76 }, { 122, 24, 40 } }, yellow = { { 220, 170, 40 }, { 252, 208, 90 }, { 156, 112, 28 } }, blue = { { 48, 96, 190 }, { 100, 150, 232 }, { 30, 62, 130 } } } local BUSES = { orange = { { 226, 136, 36 }, { 250, 176, 64 }, { 186, 96, 30 } }, green = { { 52, 150, 110 }, { 96, 192, 150 }, { 30, 98, 76 } } } local COAT, BUS = COATS.red, BUSES.orange local NDROP = 36 local SPR = {} local function rgb3(c) return c[1], c[2], c[3] end local CH = { h = { 58, 30, 38 }, H = { 104, 60, 66 }, s = { 246, 212, 188 }, e = { 30, 20, 32 }, p = { 236, 150, 150 }, w = { 242, 238, 232 }, k = { 28, 24, 34 }, } local function compile(rows) local runs, open = {}, {} for y, row in ipairs(rows) do assert(#row == 9, "sprite row " .. y) local seen = {} local x = 1 while x <= 9 do local ch = row:sub(x, x) local x2 = x while x2 < 9 and row:sub(x2 + 1, x2 + 1) == ch do x2 = x2 + 1 end if ch ~= "." then local key = x .. ":" .. x2 .. ":" .. ch seen[key] = true local r = open[key] if r then r.h = r.h + 1 else r = { x = x - 1, y = y - 1, w = x2 - x + 1, h = 1, c = ch }; open[key] = r; runs[#runs + 1] = r end end x = x2 + 1 end for key in pairs(open) do if not seen[key] then open[key] = nil end end end return runs end local ART = { front = { "..hhhhh..", ".hhHHhhh.", "hhhhhhhhh", "hhssssshh", "hhesssehh", "hhpsssphh", "hhhssshhh", ".hhwwwhh.", "hrrwwwrrh", "hrRrwrRrh", "hrrrwrrrh", "hrrrrrrrh", ".crrrrrc.", "..kk.kk.." }, look = { "..hhhhh..", ".hhHHhhh.", "hhhhhhhhh", "hssssshhh", "hesssehhh", "hpsssphhh", "hhsssshhh", ".hhwwwhh.", "hrrwwwrrh", "hrRrwrRrh", "hrrrwrrrh", "hrrrrrrrh", ".crrrrrc.", "..kk.kk.." }, sideA = { "..hhhhh..", ".hhHHhhh.", "hhhhhhhhh", "hssshhhhh", "sesshhhhh", "spsshhhh.", ".sssshhh.", "..wwrhh..", ".rrwwrrh.", ".rRwrrrhh", ".rrrrrrrh", ".rrrrrrr.", ".crrrrrc.", "..kk..kk." }, sideB = { "..hhhhh..", ".hhHHhhh.", "hhhhhhhhh", "hssshhhhh", "sesshhhhh", "spsshhhh.", ".sssshhh.", "..wwrhh..", ".rrwwrrh.", ".rRwrrrhh", ".rrrrrrrh", ".rrrrrrr.", ".crrrrrc.", "...kkkk.." }, backA = { "..hhhhh..", ".hhhHhhh.", "hhhhhhhhh", "hhhhhhhhh", "hhhhhhhhh", "hhhhhhhhh", "hhhhhhhhh", ".hhhhhhh.", "hhrrrrrhh", "hrrRrrRrh", "hrrrrrrrh", "hrrrrrrrh", ".crrrrrc.", "..kk.kk.." }, backB = { "..hhhhh..", ".hhhHhhh.", "hhhhhhhhh", "hhhhhhhhh", "hhhhhhhhh", "hhhhhhhhh", "hhhhhhhhh", ".hhhhhhh.", "hhrrrrrhh", "hrrRrrRrh", "hrrrrrrrh", "hrrrrrrrh", ".crrrrrc.", "..kk..kk." }, } function on_settings() COAT, BUS = COATS[cfg.coat] or COATS.red, BUSES[cfg.bus] or BUSES.orange CH.r, CH.R, CH.c = COAT[1], COAT[2], COAT[3] NDROP = (cfg.rain or 3) * 12 if not SPR.front then for k, v in pairs(ART) do SPR[k] = compile(v) end end end local function B(x, y, w, h, r, g, b) local i = floor(x) local f = x - i if f < 0.04 then rect(i, y, w, h, r, g, b) return end blend_rect(i, y, 1, h, r, g, b, 1 - f) if w > 1 then rect(i + 1, y, w - 1, h, r, g, b) end blend_rect(i + w, y, 1, h, r, g, b, f) end local function bar(x, y, w, h, r, g, b, a) local x1 = x + w local i, i1 = floor(x), floor(x1) if i1 == i then blend_rect(i, y, 1, h, r, g, b, a * (x1 - x)) return end blend_rect(i, y, 1, h, r, g, b, a * (i + 1 - x)) if i1 > i + 1 then blend_rect(i + 1, y, i1 - i - 1, h, r, g, b, a) end if x1 - i1 > 0.02 then blend_rect(i1, y, 1, h, r, g, b, a * (x1 - i1)) end end local function girl(sp, gx, gy) for k = 1, #sp do local r = sp[k] local c = CH[r.c] B(gx + r.x, gy + r.y, r.w, r.h, c[1], c[2], c[3]) end end local BG = nil local ASPH1, ASPH2 = { 76, 82, 98 }, { 56, 60, 76 } local function mix(a, b, t) return floor(a[1] + (b[1] - a[1]) * t + 0.5), floor(a[2] + (b[2] - a[2]) * t + 0.5), floor(a[3] + (b[3] - a[3]) * t + 0.5) end local function disc(cx, cy, r, c, a) for dy = -r, r do local hw = floor(sqrt(r * r - dy * dy)) blend_rect(cx - hw, cy + dy, 2 * hw + 1, 1, c[1], c[2], c[3], a) end end local function build() for y = 0, 23 do rect(0, y, W, 1, mix({ 70, 84, 112 }, { 130, 146, 170 }, y / 23)) end local x = 0 for i = 1, 12 do local h = hash32(i * 0x9E3779B1) local w = 6 + (h & 3) rect(x, 4 + ((h >> 4) & 7), w, 22, 98, 110, 138) x = x + w end x = 3 for i = 21, 32 do local h = hash32(i * 0x9E3779B1) local w = 5 + (h & 3) local top = 12 + ((h >> 4) & 5) rect(x, top, w, 14, 82, 94, 122) if (h >> 8) & 1 == 1 then px(x + 1, top + 2 + ((h >> 10) & 3), 255, 214, 130) end if (h >> 9) & 1 == 1 then px(x + w - 2, top + 5 + ((h >> 12) & 3), 255, 214, 130) end x = x + w + 1 end for y = 24, 41 do rect(0, y, W, 1, mix(ASPH1, ASPH2, (y - 24) / 17)) end for x0 = 2, W, 9 do rect(x0, 40, 4, 1, 150, 156, 172) end rect(0, 42, W, 1, 128, 134, 150) rect(0, 43, W, 1, 88, 92, 108) for y = 44, H - 1 do rect(0, y, W, 1, mix({ 100, 106, 124 }, { 84, 90, 110 }, (y - 44) / 19)) end for y = 52, H - 1, 8 do rect(0, y, W, 1, 70, 76, 96) end for x0 = 4, W, 11 do rect(x0, 44, 1, 8, 70, 76, 96); rect(x0 + 5, 52, 1, 8, 70, 76, 96) end rect(56, 8, 1, 32, 36, 38, 52) rect(51, 8, 6, 1, 36, 38, 52) rect(50, 8, 3, 2, 255, 226, 160) disc(51, 10, 7, { 255, 214, 140 }, 0.10) disc(51, 10, 4, { 255, 214, 140 }, 0.12) for y = 30, 41, 2 do blend_rect(50, y, 3, 1, 255, 214, 140, 0.18) end blend_rect(3, 42, 26, 20, 190, 214, 232, 0.10) rect(5, 46, 7, 8, 206, 220, 232) rect(6, 48, 5, 1, 120, 134, 152); rect(6, 50, 5, 1, 120, 134, 152); rect(6, 52, 4, 1, 120, 134, 152) rect(20, 54, 9, 2, 122, 84, 52) rect(21, 56, 1, 4, 74, 50, 34); rect(27, 56, 1, 4, 74, 50, 34) rect(1, 39, 31, 3, 46, 54, 72) rect(1, 39, 31, 1, 140, 154, 176) rect(1, 41, 2, 22, 46, 54, 72) rect(29, 41, 2, 22, 46, 54, 72) rect(45, 46, 1, 17, 70, 76, 94) rect(44, 39, 3, 1, 40, 96, 176); rect(43, 40, 5, 5, 40, 96, 176); rect(44, 45, 3, 1, 40, 96, 176) rect(44, 41, 3, 2, 240, 244, 250) BG = gfx.snapshot(0, 0, W, H) end local function bus(bx, o, boarded) local c1, c2, c3 = BUS[1], BUS[2], BUS[3] B(bx + 5, 17, 12, 2, 255, 196, 84) B(bx + 1, 19, 38, 1, c2[1], c2[2], c2[3]) B(bx, 20, 40, 15, c1[1], c1[2], c1[3]) B(bx, 32, 40, 3, c3[1], c3[2], c3[3]) B(bx + 1, 35, 38, 1, 120, 60, 34) B(bx + 2, 21, 5, 7, 255, 206, 120) B(bx + 4, 23, 2, 2, 90, 52, 40); B(bx + 3, 25, 4, 3, 90, 52, 40) for k = 0, 2 do local wx = bx + 18 + k * 7 B(wx, 21, 6, 7, 255, 206, 120) if k == 1 then B(wx + 2, 23, 2, 2, 110, 64, 46); B(wx + 1, 25, 4, 3, 110, 64, 46) end if k == 2 then B(wx + 2, 24, 2, 2, 110, 64, 46); B(wx + 1, 26, 4, 2, 110, 64, 46) end if k == 0 and boarded then B(wx + 2, 23, 2, 2, 58, 30, 38); B(wx + 1, 25, 4, 3, COAT[1][1], COAT[1][2], COAT[1][3]) end end B(bx + 9, 21, 6, 14, 40, 30, 34) B(bx + 9, 33, 6, 1, 214, 160, 92) local pw = 3 * (1 - o) if pw > 0.05 then B(bx + 9, 21, pw, 14, 88, 120, 150) B(bx + 15 - pw, 21, pw, 14, 98, 130, 160) end B(bx + 8, 21, 1, 14, c3[1], c3[2], c3[3]); B(bx + 15, 21, 1, 14, c3[1], c3[2], c3[3]) for _, wx in ipairs({ 8, 31 }) do B(bx + wx - 2, 33, 4, 1, 22, 22, 28) B(bx + wx - 3, 34, 6, 4, 22, 22, 28) B(bx + wx - 2, 38, 4, 1, 22, 22, 28) B(bx + wx - 1, 35, 2, 2, 168, 168, 180) end B(bx, 29, 1, 2, 255, 246, 196) B(bx + 39, 29, 1, 2, 255, 70, 50) bar(bx - 5, 29, 5, 2, 255, 238, 180, 0.28) bar(bx - 10, 28, 5, 4, 255, 238, 180, 0.12) bar(bx - 15, 28, 5, 4, 255, 238, 180, 0.06) end local DX, DS, DL, DO = {}, {}, {}, {} for i = 1, 60 do local h = hash32(i * 0x9E3779B1) DX[i] = h & 63 DS[i] = (i % 2 == 0) and 2.3 or 1.7 DL[i] = (i % 2 == 0) and 4 or 3 DO[i] = (h >> 8) & 255 end local SPL = {} for i = 1, 12 do local h = hash32(i * 0x85EBCA6B) SPL[i] = { 32 + (h & 31), (i <= 4) and (40 + (h >> 8) % 2) or (46 + (h >> 8) % 16), 6 + (h >> 12) % 7, (h >> 16) & 15 } end local function rain() for i = 1, NDROP do local x = DX[i] local y = floor((DO[i] + frame * DS[i]) % (H + 12)) - 6 local len = DL[i] if x >= 1 and x <= 31 and y + len > 39 then len = 39 - y end if len > 0 then blend_rect(x, y, 1, len, 206, 220, 240, i % 2 == 0 and 0.55 or 0.35) end end for i = 1, #SPL * NDROP // 60 do local s = SPL[i] local k = (frame + s[4]) % s[3] if k < 2 then px(s[1], s[2], 190, 206, 226) elseif k < 4 then px(s[1] - 1, s[2], 150, 166, 190); px(s[1] + 1, s[2], 150, 166, 190) end end end function render() if not BG then build() end if not SPR.front then for k, v in pairs(ART) do SPR[k] = compile(v) end end gfx.blit_rgb(BG, 0, 0, W, H) local t = ((frame + T0) / FPS) % CY local bx if t >= 0.5 and t < 11 then bx = t < 6 and XS + 66 * (1 - (t - 0.5) / 5.5) ^ 2 or XS elseif t >= 11 then bx = XS - 7 * (t - 11) ^ 2 if bx < -42 then bx = nil end end if bx then local o = t < 6 and 0 or (t < 6.6 and (t - 6) / 0.6 or (t < 9.6 and 1 or max(0, 1 - (t - 9.6) / 0.6))) bus(bx, o, t >= 9.4) end local sp, gx, gy, fade if t >= 19 and t < 23.4 then sp, gx, gy = SPR[floor(t * 5) % 2 == 0 and "sideA" or "sideB"], 74 - 63 * (t - 19) / 4.4, 47 elseif t >= 23.4 or t < 4.4 then sp, gx, gy = SPR.front, 11, 47 elseif t < 6.8 then sp, gx, gy = SPR.look, 11, 47 elseif t < 8.7 then local u = (t - 6.8) / 1.9 sp, gx, gy = SPR[floor(t * 5) % 2 == 0 and "backA" or "backB"], 11 - 2 * u, 47 - 22 * u elseif t < 9.4 then sp, gx, gy, fade = SPR.backA, 9, 25, (t - 8.7) / 0.7 end if sp then girl(sp, gx, floor(gy + 0.5)) if fade then blend_rect(floor(gx), 25, 10, 14, 40, 30, 34, fade) end end rain() end