info = { type = "image", title = "Gallery wall", category = "city", author = "BRRRO", version = "1.0", license = "MIT", desc = "Camera pans along a gallery wall of paintings", api = 33, } local tr = ({ sk = { ["Visitor"] = "Návštevník", ["Pan speed"] = "Rýchlosť posunu", ["Wall"] = "Stena", ["Plum"] = "Slivková", ["Sage"] = "Šalviová", ["Slate"] = "Bridlicová" }, cs = { ["Visitor"] = "Návštěvník", ["Pan speed"] = "Rychlost posunu", ["Wall"] = "Stěna", ["Plum"] = "Švestková", ["Sage"] = "Šalvějová", ["Slate"] = "Břidlicová" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "visitor", label = T("Visitor"), type = "bool", default = true }, { key = "speed", label = T("Pan speed"), type = "int", min = 1, max = 5, default = 3 }, { key = "wall", label = T("Wall"), type = "int", default = "plum", opts = { keys = { "plum", "sage", "slate" }, T("Plum"), T("Sage"), T("Slate") } }, } local rect, blend_rect, px = gfx.rect, gfx.blend_rect, gfx.px local floor = math.floor local W, H, FPS = gfx.W, gfx.H, gfx.FPS local P = 192 local WALLS = { plum = { 98, 84, 118 }, sage = { 86, 116, 102 }, slate = { 84, 98, 126 }, } local WARM = { 255, 238, 190 } local GOLD, GOLD_L, GOLD_D = { 176, 132, 52 }, { 224, 186, 98 }, { 112, 80, 32 } local CREAM = { 238, 226, 198 } local OX, WALL = 0, WALLS.plum local function box(x, y, w, h, c) rect(x - OX, y, w, h, c[1], c[2], c[3]) end local function dot(x, y, c) px(x - OX, y, c[1], c[2], c[3]) end local function wash(x, y, w, h, c, a) blend_rect(x - OX, y, w, h, c[1], c[2], c[3], a) end local function frame3(x, y, w, h, fc, fl, fd) box(x, y, w, h, fc); box(x, y, w, 1, fl); box(x, y, 1, h, fl) box(x, y + h - 1, w, 1, fd); box(x + w - 1, y, 1, h, fd) end local function rose() frame3(8, 13, 20, 30, GOLD, GOLD_L, GOLD_D) box(10, 15, 16, 26, CREAM) local RED, RED_D, RED_L = { 196, 30, 52 }, { 132, 14, 40 }, { 246, 104, 118 } local rows = { { 18, 15, 20 }, { 19, 14, 21 }, { 20, 13, 22 }, { 21, 13, 22 }, { 22, 13, 22 }, { 23, 13, 22 }, { 24, 13, 22 }, { 25, 14, 21 }, { 26, 15, 20 }, { 27, 16, 19 } } for i = 1, #rows do local r = rows[i]; box(r[2], r[1], r[3] - r[2] + 1, 1, RED) end box(18, 19, 1, 7, RED_D); box(20, 22, 2, 4, RED_D); box(16, 26, 4, 1, RED_D) box(14, 20, 2, 2, RED_L); box(15, 19, 2, 1, RED_L) box(18, 28, 1, 10, { 52, 122, 62 }) box(14, 32, 4, 1, { 96, 164, 84 }); box(15, 31, 2, 1, { 96, 164, 84 }) box(19, 34, 4, 1, { 96, 164, 84 }); box(20, 33, 2, 1, { 96, 164, 84 }) end local function sea() frame3(38, 20, 28, 20, GOLD, GOLD_L, GOLD_D) box(40, 22, 24, 6, { 160, 206, 244 }); box(40, 25, 24, 3, { 190, 224, 248 }) box(40, 28, 24, 10, { 34, 108, 176 }); box(40, 34, 24, 4, { 24, 84, 150 }) for i = 0, 5 do dot(43 + i * 4, 30 + i % 3 * 2, { 126, 192, 232 }); dot(44 + i * 4, 30 + i % 3 * 2, { 126, 192, 232 }) end box(55, 24, 3, 3, { 255, 240, 182 }); box(56, 29, 1, 5, { 220, 220, 190 }) box(46, 31, 7, 1, { 96, 54, 32 }); box(47, 32, 5, 1, { 70, 40, 26 }) box(49, 26, 1, 5, { 60, 40, 30 }); box(50, 26, 3, 4, { 250, 250, 244 }); box(46, 28, 3, 2, { 232, 232, 226 }) end local function cat() local wood, wl, wd = { 100, 62, 36 }, { 142, 96, 58 }, { 62, 38, 24 } frame3(82, 14, 24, 28, wood, wl, wd) local OR, ST, WH, K = { 230, 136, 52 }, { 176, 86, 28 }, { 250, 236, 212 }, { 22, 20, 26 } box(84, 16, 20, 24, { 40, 84, 78 }) box(87, 32, 14, 8, OR); box(92, 33, 4, 7, WH) box(90, 31, 8, 1, { 196, 36, 60 }); dot(93, 32, { 250, 210, 70 }) box(89, 23, 10, 9, OR); box(89, 20, 3, 3, OR); box(97, 20, 3, 3, OR) dot(90, 21, { 238, 150, 160 }); dot(98, 21, { 238, 150, 160 }) box(94, 23, 1, 2, ST); box(92, 24, 1, 1, ST); box(96, 24, 1, 1, ST); box(90, 29, 1, 2, ST); box(98, 29, 1, 2, ST) box(91, 26, 2, 2, { 190, 230, 80 }); box(96, 26, 2, 2, { 190, 230, 80 }) box(92, 26, 1, 2, K); box(96, 26, 1, 2, K) box(93, 29, 3, 2, WH); dot(94, 29, { 240, 130, 140 }) box(88, 29, 1, 1, WH); box(99, 29, 1, 1, WH) end local function abstract() box(124, 17, 24, 24, { 28, 26, 32 }); box(125, 18, 22, 22, { 238, 234, 224 }) box(127, 20, 18, 18, { 30, 36, 104 }) local disc = { { 22, 133, 137 }, { 23, 132, 138 }, { 24, 131, 139 }, { 25, 131, 139 }, { 26, 131, 139 }, { 27, 131, 139 }, { 28, 132, 138 }, { 29, 133, 137 } } for i = 1, #disc do local r = disc[i]; box(r[2], r[1], r[3] - r[2] + 1, 1, { 244, 140, 40 }) end for i = 0, 17 do box(127 + i, 37 - i, 2, 1, { 56, 196, 186 }) end box(139, 32, 5, 5, { 240, 100, 150 }); box(129, 22, 2, 2, { 250, 220, 70 }); box(127, 30, 18, 1, { 226, 228, 250 }) end local function hills() frame3(156, 12, 24, 30, { 184, 186, 198 }, { 226, 228, 238 }, { 118, 120, 138 }) for y = 14, 39 do local t = (y - 14) / 25 box(158, y, 20, 1, { floor(34 + 66 * t), floor(34 + 46 * t), floor(96 + 44 * t) }) end local moon = { { 19, 169, 171 }, { 20, 168, 172 }, { 21, 168, 172 }, { 22, 169, 171 } } for i = 1, #moon do local r = moon[i]; box(r[2], r[1], r[3] - r[2] + 1, 1, { 250, 242, 196 }) end for x = 158, 177 do local far = 29 - floor(3 * math.sin(x * 0.35) + 0.5) local near = 34 - floor(2 * math.sin(x * 0.55 + 1) + 0.5) box(x, far, 1, 40 - far, { 74, 62, 128 }) box(x, near, 1, 40 - near, { 36, 34, 84 }) end dot(164, 36, { 252, 214, 100 }); dot(160, 16, { 240, 240, 255 }); dot(175, 15, { 240, 240, 255 }); dot(163, 19, { 240, 240, 255 }) end local ART = { { 18, 43, rose }, { 52, 40, sea }, { 94, 42, cat }, { 136, 41, abstract }, { 168, 42, hills }, } local HALF = { 10, 14, 12, 12, 12 } local function scene() box(0, 0, P, 6, { 34, 30, 44 }); box(0, 4, P, 1, { 74, 70, 90 }) box(0, 6, P, 46, WALL) local dark = { WALL[1] * 0.8, WALL[2] * 0.8, WALL[3] * 0.8 } box(0, 47, P, 5, { floor(dark[1]), floor(dark[2]), floor(dark[3]) }) box(0, 46, P, 1, { WALL[1] + 40, WALL[2] + 40, WALL[3] + 40 }) box(0, 52, P, 2, { 36, 32, 44 }); box(0, 54, P, 10, { 72, 48, 36 }); box(0, 54, P, 1, { 100, 70, 52 }) for x = 0, P - 1, 16 do box(x, 55, 1, 3, { 50, 32, 26 }); box(x + 8, 58, 1, 3, { 50, 32, 26 }); box(x + 4, 61, 1, 3, { 50, 32, 26 }) end for i = 1, #ART do local a = ART[i] local cx = a[1] if cx + 16 > OX and cx - 16 < OX + 64 then local bot = a[2] local hw = HALF[i] for y = 6, bot + 3 do local h = 2 + (hw - 2) * (y - 6) / (bot - 3) wash(floor(cx - h), y, floor(2 * h), 1, WARM, 0.09) wash(floor(cx - h * 0.6), y, floor(1.2 * h), 1, WARM, 0.07) end wash(cx - 10, 55, 20, 2, WARM, 0.10); wash(cx - 6, 57, 12, 1, WARM, 0.08) end end box(36, 49, 24, 1, { 106, 76, 56 }); box(36, 50, 24, 2, { 52, 38, 34 }); box(38, 52, 2, 6, { 40, 30, 28 }); box(56, 52, 2, 6, { 40, 30, 28 }) for i = 1, #ART do local a = ART[i] if a[1] + 16 > OX and a[1] - 16 < OX + 64 then a[3]() local x0 = a[1] box(x0 - 3, a[2] + 3, 6, 2, { 206, 202, 190 }); box(x0 - 2, a[2] + 4, 3, 1, { 150, 146, 138 }) box(x0 - 2, 4, 4, 2, { 20, 18, 26 }); box(x0 - 1, 5, 2, 1, WARM) end end end local CH, STAGE = {}, 1 function on_settings() WALL = WALLS[cfg.wall] or WALLS.plum CH, STAGE = {}, 1 end local TB1, TD, TB2, TA = 9.1, 5.0, 14.0, 19.2 local CYC = TB1 + TD + TB2 + TA local XS, VV = 116, 126 / 9.1 local function hermite(p0, v0, p1, v1, T, u) local u2, u3 = u * u, u * u * u return T * v0 * (u3 - 2 * u2 + u) + p0 * (2 * u3 - 3 * u2 + 1) + p1 * (3 * u2 - 2 * u3) + T * v1 * (u3 - u2) end local function camera(t) if t < TB1 then return hermite(0, 10, 66, 0, TB1, t / TB1) end if t < TB1 + TD then return 66 end local t3 = t - TB1 - TD if t3 < TB2 then return hermite(66, 0, 192, 10, TB2, t3 / TB2) end return 192 + 10 * (t3 - TB2) end local function frect(x, y, w, h, r, g, b) local ix = floor(x) local f = x - ix if f < 0.06 then rect(ix, y, w, h, r, g, b) return end if w > 1 then rect(ix + 1, y, w - 1, h, r, g, b) end blend_rect(ix, y, 1, h, r, g, b, 1 - f) blend_rect(ix + w, y, 1, h, r, g, b, f) end local function figure(x, d, ph, chin) local y = 32 blend_rect(floor(x), 58, 7, 1, 0, 0, 0, 0.25) frect(x + 1, y, 4, 5, 22, 18, 32) frect(x + (d > 0 and 5 or 0), y + 2, 1, 1, 22, 18, 32) frect(x, y + 5, 6, 11, 22, 18, 32) if chin then frect(x + (d > 0 and 5 or -1), y + 6, 2, 3, 22, 18, 32) end if ph == 0 then frect(x, y + 16, 2, 10, 22, 18, 32); frect(x + 4, y + 16, 2, 10, 22, 18, 32) else frect(x + 1, y + 16, 4, 10, 22, 18, 32) end end function render() if STAGE <= 3 then OX = (STAGE - 1) * 64 scene() CH[STAGE] = gfx.snapshot(0, 0, W, H) STAGE = STAGE + 1 end local t = frame / FPS * (0.4 + 0.2 * (cfg.speed or 3)) % CYC local c = floor(camera(t)) % P gfx.clear(WALL[1], WALL[2], WALL[3]) for k = 1, #CH do local sx = (k - 1) * 64 - c if sx > -64 and sx < 64 then gfx.blit_rgb(CH[k], sx, 0, 64, 64) end if sx + P < 64 then gfx.blit_rgb(CH[k], sx + P, 0, 64, 64) end end if cfg.visitor == false then return end local cw = floor(camera(t)) if t < TB1 + TD + TB2 then local v if t < TB1 then v = -10 + VV * t elseif t < TB1 + TD then v = XS else v = XS + VV * (t - TB1 - TD) end local sx = v - cw if sx > -8 and sx < 66 then local moving = t < TB1 or t >= TB1 + TD figure(sx, 1, moving and floor(v / 4) % 2 or 0, not moving and t > TB1 + 1 and t < TB1 + TD - 0.8) end elseif t > TB1 + TD + TB2 + 3 then local sx = 70 - 24 * (t - TB1 - TD - TB2 - 3) if sx > -8 then figure(sx, -1, floor(sx / 4) % 2, false) end end end