info = { type = "image", title = "Balcony rise", category = "city", author = "BRRRO", version = "1.0", license = "MIT", desc = "Climbing a block of flats, balcony by balcony", api = 44, } local tr = ({ sk = { ["Time"] = "Čas", ["Day"] = "Deň", ["Evening"] = "Večer", ["Camera"] = "Kamera", ["Calm"] = "Pokojná", ["Brisk"] = "Rýchla" }, cs = { ["Time"] = "Čas", ["Day"] = "Den", ["Evening"] = "Večer", ["Camera"] = "Kamera", ["Calm"] = "Klidná", ["Brisk"] = "Rychlá" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "time", label = T("Time"), type = "int", default = "day", opts = { keys = { "day", "evening" }, T("Day"), T("Evening") } }, { key = "cam", label = T("Camera"), type = "int", default = "calm", opts = { keys = { "calm", "brisk" }, T("Calm"), T("Brisk") } }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local blit_rgb, snapshot = gfx.blit_rgb, gfx.snapshot local floor, sin, max, min, abs = math.floor, math.sin, math.max, math.min, math.abs local hash32 = math.hash32 local W, H = gfx.W, gfx.H local FH, NF = 28, 5 local FY0 = 62 local GY0 = FY0 + NF * FH local WH = GY0 + 26 local function fy(n) return FY0 + (NF - n) * FH end local function lerp(a, b, t) return a + (b - a) * t end local function rgb(r, g, b) return floor(r + 0.5), floor(g + 0.5), floor(b + 0.5) end local function mix(a, b, t) return rgb(lerp(a[1], b[1], t), lerp(a[2], b[2], t), lerp(a[3], b[3], t)) end local function c3(c) return c[1], c[2], c[3] end local PALS = { day = { skyT = { 84, 160, 236 }, skyB = { 196, 230, 252 }, plaster = { 238, 208, 162 }, shade = { 206, 174, 132 }, seam = { 218, 188, 144 }, back = { 250, 230, 196 }, glass = { 124, 166, 212 }, lit = { 255, 214, 120 }, cloud = { 255, 255, 255 }, cloudA = 0.85, wall = { 192, 156, 124 } }, evening = { skyT = { 58, 66, 140 }, skyB = { 255, 170, 108 }, plaster = { 220, 164, 128 }, shade = { 180, 128, 106 }, seam = { 196, 142, 114 }, back = { 236, 190, 154 }, glass = { 70, 84, 140 }, lit = { 255, 208, 110 }, cloud = { 255, 196, 160 }, cloudA = 0.8, wall = { 168, 120, 100 } }, } local P = PALS.day local LIT = { { true, true }, { true, false }, { false, true }, { true, true }, { false, true } } local SLAB = { { 150, 172, 140 }, { 204, 148, 140 }, { 136, 156, 186 }, { 206, 176, 104 }, { 110, 160, 160 } } local RAIL = { { 84, 88, 100 }, { 238, 238, 242 }, { 96, 128, 100 }, { 120, 84, 64 }, { 80, 96, 128 } } local FRAME = { 244, 240, 232 } local SKIN = { 234, 190, 156 } local function head(x, y, hair) rect(x - 1, y - 2, 3, 5, c3(SKIN)); rect(x - 2, y - 1, 5, 3, c3(SKIN)) rect(x - 2, y - 3, 5, 2, c3(hair)) px(x - 1, y, 60, 44, 50); px(x + 1, y, 60, 44, 50) end local EVEN local function floor_slice(i) rect(0, 0, W, 28, c3(P.plaster)) rect(0, 0, W, 2, c3(P.shade)) rect(1, 2, 1, 23, c3(P.seam)); rect(62, 2, 1, 23, c3(P.seam)) rect(5, 2, 54, 23, c3(P.back)) for s = 1, 2 do local wx = s == 1 and 8 or 42 local lit = EVEN and LIT[i][s] rect(wx - 1, 3, 16, 19, c3(FRAME)) rect(wx, 4, 14, 17, c3(lit and P.lit or P.glass)) rect(wx + 6, 4, 1, 17, c3(FRAME)); rect(wx, 11, 14, 1, c3(FRAME)) end if i == 1 then head(29, 8, { 238, 238, 246 }); rect(28, 3, 3, 2, 238, 238, 246) rect(26, 11, 7, 7, 170, 110, 150) elseif i == 4 then head(32, 9, { 110, 70, 50 }); rect(29, 11, 7, 7, 96, 140, 170) rect(25, 12, 4, 1, 96, 140, 170); rect(21, 12, 4, 1, 120, 90, 70) px(20, 11, 200, 210, 224); px(22, 11, 200, 210, 224); px(21, 10, 200, 210, 224); px(21, 12, 200, 210, 224) elseif i == 5 then head(30, 8, { 70, 56, 60 }); rect(27, 11, 7, 7, 190, 150, 86) rect(32, 14, 7, 5, 176, 104, 54); rect(33, 13, 5, 7, 176, 104, 54); px(35, 16, 50, 30, 24) for k = 0, 8 do px(38 + k, 13 - (k * 5) // 8, 90, 56, 36) end rect(46, 7, 2, 2, 60, 40, 30) elseif i == 3 then rect(5, 4, 54, 1, 170, 174, 186) end local rl, sl = RAIL[i], SLAB[i] rect(5, 17, 54, 2, c3(rl)) for x = 6, 56, 3 do rect(x, 19, 1, 6, c3(rl)) end rect(5, 17, 2, 8, c3(rl)); rect(57, 17, 2, 8, c3(rl)) rect(3, 25, 58, 3, c3(sl)); rect(3, 25, 58, 1, sl[1] + 24, sl[2] + 20, sl[3] + 16) if i == 1 then rect(8, 14, 12, 5, 120, 84, 60); rect(8, 13, 12, 1, 60, 130, 70) for x = 9, 18, 3 do rect(x, 10, 2, 3, 214, 60, 76); px(x + 1, 9, 236, 120, 120) end elseif i == 2 then rect(47, 10, 6, 7, 214, 142, 84); rect(46, 6, 7, 5, 214, 142, 84) px(46, 5, 214, 142, 84); px(52, 5, 214, 142, 84) rect(47, 12, 4, 1, 176, 104, 52) elseif i == 4 then rect(7, 12, 6, 5, 176, 96, 70); rect(7, 6, 6, 6, 70, 140, 80); rect(5, 8, 10, 3, 70, 140, 80) end end local function ground_slice() rect(0, 0, W, 26, c3(P.wall)) rect(0, 0, W, 2, c3(P.shade)) rect(8, 8, 8, 7, 150, 160, 170) for x = 8, 15, 2 do rect(x, 8, 1, 7, 100, 110, 124) end rect(8, 11, 8, 1, 100, 110, 124) rect(18, 2, 28, 2, 70, 80, 96) rect(21, 4, 22, 21, 90, 70, 60) rect(23, 6, 8, 19, 120, 84, 60); rect(33, 6, 8, 19, 120, 84, 60) rect(24, 7, 6, 8, 150, 190, 210); rect(34, 7, 6, 8, 150, 190, 210) rect(30, 15, 1, 3, 214, 190, 120); rect(33, 15, 1, 3, 214, 190, 120) rect(18, 23, 28, 3, 150, 150, 158) rect(0, 22, 18, 2, 140, 140, 150); rect(46, 22, 18, 2, 140, 140, 150) rect(0, 24, W, 2, 78, 82, 94) rect(0, 24, W, 1, 110, 112, 122) for _, b in ipairs({ { 4, 17, 8 }, { 48, 17, 8 }, { 54, 18, 6 } }) do rect(b[1], b[2], b[3], 5, 60, 130, 70); rect(b[1] + 1, b[2] - 1, b[3] - 2, 1, 60, 130, 70) rect(b[1] + 1, b[2] + 1, 2, 1, 96, 170, 96) end rect(61, 6, 1, 18, 60, 66, 78) rect(59, 4, 4, 3, EVEN and 255 or 214, EVEN and 230 or 214, EVEN and 150 or 196) end local function sky_roof() for y = 0, 39 do rect(0, y, W, 1, mix(P.skyT, P.skyB, y / 39)) end rect(0, 40, W, 22, c3(P.skyB)) rect(28, 42, 6, 10, 156, 100, 84); rect(27, 41, 8, 2, 120, 76, 66) rect(44, 34, 1, 18, 90, 94, 108) rect(40, 38, 9, 1, 90, 94, 108); rect(41, 41, 7, 1, 90, 94, 108); rect(42, 44, 5, 1, 90, 94, 108) rect(13, 47, 7, 5, 214, 218, 226); rect(14, 46, 5, 1, 214, 218, 226); rect(16, 51, 1, 2, 90, 94, 108) rect(0, 52, W, 2, 226, 218, 210) rect(0, 54, W, 8, c3(P.plaster)); rect(0, 54, W, 2, c3(P.shade)) rect(1, 56, 1, 6, c3(P.seam)); rect(62, 56, 1, 6, c3(P.seam)) end local SL, TOP, GRD = {}, nil, nil local STAGE = 1 local function stages(n) if n == 1 then sky_roof(); TOP = snapshot(0, 0, W, 62) elseif n <= 6 then floor_slice(n - 1); SL[n - 1] = snapshot(0, 0, W, FH) else ground_slice(); GRD = snapshot(0, 0, W, 26) end end local STOPS = { { 164, 150 }, { 128, 110 }, { 100, 110 }, { 72, 110 }, { 44, 110 }, { 0, 150 }, { 44, 40 }, { 72, 60 }, { 128, 60 } } local TL, TOT = {}, 0 local function timeline() local brisk = cfg.cam == "brisk" local v = brisk and 0.85 or 0.55 TL, TOT = {}, 0 for i = 1, #STOPS do local a, b = STOPS[i], STOPS[i % #STOPS + 1] local dwell = floor(a[2] * (brisk and 0.6 or 1)) local mv = floor(abs(b[1] - a[1]) / v) TL[i] = { t0 = TOT, dwell = dwell, mv = mv, a = a[1], b = b[1] } TOT = TOT + dwell + mv end end local function camera(f) f = f % TOT for i = 1, #TL do local s = TL[i] if f < s.t0 + s.dwell then return s.a end if f < s.t0 + s.dwell + s.mv then local u = (f - s.t0 - s.dwell) / s.mv return s.a + (s.b - s.a) * u * u * (3 - 2 * u) end end return STOPS[1][1] end function on_settings() P = PALS[cfg.time] or PALS.day EVEN = cfg.time == "evening" STAGE = 1 timeline() end local function sh(f) if f < 0.25 then return 0 elseif f > 0.75 then return 1 end return (f - 0.25) * 2 end local function dot(x, y, r, g, b, a) local ix, iy = floor(x), floor(y) local fx, fy = sh(x - ix), sh(y - iy) local w = (1 - fx) * (1 - fy) * a if w > 0.08 then blend(ix, iy, r, g, b, w) end w = fx * (1 - fy) * a if w > 0.08 then blend(ix + 1, iy, r, g, b, w) end w = (1 - fx) * fy * a if w > 0.08 then blend(ix, iy + 1, r, g, b, w) end w = fx * fy * a if w > 0.08 then blend(ix + 1, iy + 1, r, g, b, w) end end local RING1 = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } } local RING2 = { { -2, -1 }, { -2, 0 }, { -2, 1 }, { 2, -1 }, { 2, 0 }, { 2, 1 }, { -1, -2 }, { 0, -2 }, { 1, -2 }, { -1, 2 }, { 0, 2 }, { 1, 2 } } local function grandma(sy, f) local c = f % 130 local pour = c >= 45 and c < 95 rect(24, sy + (pour and 11 or 12), 3, 1, 170, 110, 150) if pour then rect(21, sy + 10, 4, 3, 98, 150, 170); rect(18, sy + 12, 3, 1, 98, 150, 170) rect(17, sy + 13 + (f % 3), 1, 2, 160, 210, 240) rect(16, sy + 14 + ((f + 1) % 3), 1, 1, 160, 210, 240) else rect(21, sy + 12, 4, 3, 98, 150, 170); rect(19, sy + 12, 2, 1, 98, 150, 170) end end local function cat(sy, f) if (f // 24) % 2 == 0 then rect(53, sy + 11, 1, 5, 214, 142, 84); px(54, sy + 10, 214, 142, 84) else rect(53, sy + 13, 2, 3, 214, 142, 84); px(55, sy + 12, 214, 142, 84) end if f % 110 < 4 then rect(47, sy + 8, 2, 1, 60, 44, 40); rect(50, sy + 8, 2, 1, 60, 44, 40) else px(48, sy + 8, 140, 200, 90); px(51, sy + 8, 140, 200, 90) end end local GARM = { { 11, 7, 7, { 214, 226, 240 }, 0.0 }, { 24, 8, 9, { 210, 150, 140 }, 1.3 }, { 38, 2, 5, { 120, 150, 200 }, 2.2 }, { 42, 2, 5, { 120, 150, 200 }, 2.5 }, { 47, 7, 10, { 110, 126, 150 }, 3.4 }, } local function laundry(sy, f) local gust = sin(f * 0.011) > 0.55 and 2 or 1 for k = 1, #GARM do local g = GARM[k] local o = floor(gust * 1.2 * sin(f * 0.07 + g[5]) + 0.5) local c = g[4] rect(g[1] + o, sy + 5, g[2], g[3], c3(c)) rect(g[1] + o, sy + 4 + g[3], g[2], 1, c[1] - 30, c[2] - 30, c[3] - 30) px(g[1] + o, sy + 4, 120, 90, 60) end end local function bubbles(sy, f) for j = max(0, (f - 125) // 26), f // 26 do local a = f - j * 26 local x, y = 21 - 0.28 * a + 2.2 * sin(a * 0.06 + j), sy + 11 - 0.34 * a if a < 112 then local ring = (j % 2 == 0) and RING2 or RING1 for k = 1, #ring do dot(x + ring[k][1], y + ring[k][2], 214, 238, 255, 0.8) end elseif a < 116 then local d = (a - 111) * 1.1 dot(x - d, y, 230, 244, 255, 0.7); dot(x + d, y, 230, 244, 255, 0.7) dot(x, y - d, 230, 244, 255, 0.7); dot(x, y + d, 230, 244, 255, 0.7) end end end local NOTE = { { 230, 120, 140 }, { 240, 200, 90 } } local function guitar(sy, f) rect(34, sy + 14 + (f // 6) % 2, 2, 1, c3(SKIN)) for j = max(0, (f - 100) // 28), f // 28 do local a = f - j * 28 if a < 95 then local x, y = 38 + 0.26 * a + 2 * sin(a * 0.07 + j), sy + 12 - 0.30 * a local c, al = NOTE[j % 2 + 1], a < 65 and 1 or (95 - a) / 30 dot(x, y, c[1], c[2], c[3], al); dot(x + 1, y, c[1], c[2], c[3], al) for s = 1, 3 do dot(x + 1, y - s, c[1], c[2], c[3], al) end end end end local function window_light(sy, f) local c = f % 1000 local a = min(1, max(0, (c - 250) / 12), max(0, (750 - c) / 12)) if a > 0 then blend_rect(8, sy + 4, 14, 17, P.lit[1], P.lit[2], P.lit[3], a * 0.95) end end local PIG = { { 8, 3 }, { 52, 5 } } local CLOUDS = { { 7, 18, 0.10, 6 }, { 17, 14, -0.07, 40 }, { 27, 20, 0.12, 22 } } local function cloud_row(xl, xr, y, a) local il, ir = floor(xl), floor(xr) if ir <= il then return end local c = P.cloud blend_rect(il + 1, y, ir - il - 1, 1, c[1], c[2], c[3], a) blend(il, y, c[1], c[2], c[3], a * (1 - (xl - il))) blend(ir, y, c[1], c[2], c[3], a * (xr - ir)) end local function roof(sy, f) for k = 1, #PIG do local p = PIG[k] local bob = ((f // 18) + p[2]) % 3 == 0 and 1 or 0 local x, y = p[1], sy + 52 rect(x, y - 3, 6, 3, 142, 150, 172); rect(x + 1, y - 3, 3, 1, 110, 118, 140) rect(x + 5, y - 5 + bob, 2, 2, 120, 128, 152); rect(x - 1, y - 2, 1, 2, 110, 118, 140) px(x + 6, y - 4 + bob, 30, 30, 40) end if (f // 20) % 2 == 0 then px(44, sy + 33, 255, 60, 60) end local c = f % 540 if c < 100 then local x, y = c - 10, sy + 44 + floor(2 * sin(c * 0.08) + 0.5) rect(x, y, 4, 2, 142, 150, 172) if (c // 4) % 2 == 0 then rect(x + 1, y - 2, 2, 2, 110, 118, 140) else rect(x + 1, y + 2, 2, 2, 110, 118, 140) end end end function render() if STAGE <= 7 then stages(STAGE) STAGE = STAGE + 1 gfx.ready(false) return end local cy = floor(camera(frame) + 0.5) blit_rgb(TOP, 0, -cy, W, 62) for n = NF, 1, -1 do local sy = fy(n) - cy if sy < H and sy + FH > 0 then blit_rgb(SL[n], 0, sy, W, FH) end end if GY0 - cy < H then blit_rgb(GRD, 0, GY0 - cy, W, 26) end if cy < 52 then local t = frame for k = 1, #CLOUDS do local c = CLOUDS[k] local x = (c[4] + t * c[3]) % (W + 2 * c[2]) - c[2] local y = c[1] - cy cloud_row(x + 3, x + c[2] - 3, y, P.cloudA) cloud_row(x, x + c[2], y + 1, P.cloudA) cloud_row(x + 2, x + c[2] - 2, y + 2, P.cloudA * 0.7) end roof(-cy, t) end for n = 1, NF do local sy = fy(n) - cy if sy < H and sy + FH > 0 then local f = frame if n == 1 then grandma(sy, f) elseif n == 2 then cat(sy, f) elseif n == 3 then laundry(sy, f) elseif n == 4 then bubbles(sy, f) else guitar(sy, f); window_light(sy, f) end end end end