info = { type = "image", title = "X-ray walk", category = "other", author = "BRRRO", version = "1.0", license = "MIT", desc = "Pets and people walk past an x-ray screen", api = 33, } local tr = ({ sk = { ["Who walks"] = "Kto chodí", ["All"] = "Všetci", ["Animals"] = "Zvieratá", ["People"] = "Ľudia", ["Pace"] = "Tempo", ["Walk"] = "Chôdza", ["Brisk"] = "Rýchlo" }, cs = { ["Who walks"] = "Kdo chodí", ["All"] = "Všichni", ["Animals"] = "Zvířata", ["People"] = "Lidé", ["Pace"] = "Tempo", ["Walk"] = "Chůze", ["Brisk"] = "Rychle" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "who", label = T("Who walks"), type = "int", default = "all", opts = { keys = { "all", "animals", "people" }, T("All"), T("Animals"), T("People") } }, { key = "pace", label = T("Pace"), type = "int", default = "walk", opts = { keys = { "walk", "brisk" }, T("Walk"), T("Brisk") } }, } local rect, blend_rect = gfx.rect, gfx.blend_rect local blit_indexed, clip = gfx.blit_indexed, gfx.clip local floor, sin, cos, max, abs = math.floor, math.sin, math.cos, math.max, math.abs local W, H = gfx.W, gfx.H local function G(w, h) local c = {} for i = 1, w * h do c[i] = 0 end return { w = w, h = h, c = c } end local function P(g, x, y, v) if x >= 0 and x < g.w and y >= 0 and y < g.h then g.c[y * g.w + x + 1] = v end end local function R(g, x, y, w, h, v) for j = y, y + h - 1 do for i = x, x + w - 1 do P(g, i, j, v) end end end local function L(g, x0, y0, x1, y1, v, th) local n = max(abs(x1 - x0), abs(y1 - y0)) for i = 0, n do local f = n == 0 and 0 or i / n local x, y = floor(x0 + (x1 - x0) * f + 0.5), floor(y0 + (y1 - y0) * f + 0.5) P(g, x, y, v) if th then P(g, x + 1, y, v) end end end local function D(g, cx, cy, r, v) for y = -r, r do for x = -r, r do if x * x + y * y <= r * r + r then P(g, cx + x, cy + y, v) end end end end local function S(g, flip) local rows = {} for y = 0, g.h - 1 do local s = string.char(table.unpack(g.c, y * g.w + 1, (y + 1) * g.w)) rows[y + 1] = flip and s:reverse() or s end return table.concat(rows) end local BONE = { 0,0,0, 196,238,232, 100,164,164, 240,255,250 } local PALS = { { 0,0,0, 206,152,92, 160,112,66, 112,68,42, 30,24,28 }, { 0,0,0, 224,140,60, 176,104,44, 170,94,36, 30,24,28 }, { 0,0,0, 232,176,132, 70,44,36, 206,92,64, 170,68,50, 44,60,120, 30,42,88, 28,24,32, 150,92,52, 98,58,34, 214,190,120, 30,24,30 }, { 0,0,0, 232,176,132, 206,170,90, 62,140,118, 44,106,90, 140,86,60, 104,62,44, 28,24,32, 150,92,52, 98,58,34, 214,190,120, 30,24,30 }, } local function quad(k, p) local dog = k == 1 local g = G(dog and 22 or 18, dog and 13 or 11) local o = G(g.w, g.h) local gr = g.h - 1 local x0, y0, x1, y1 = table.unpack(dog and { 4, 4, 14, 8 } or { 3, 3, 10, 7 }) local hx0, hy0, hx1, hy1 = table.unpack(dog and { 15, 2, 19, 6 } or { 11, 1, 14, 5 }) local amp = dog and 3 or 2 local anch = dog and { 13, 12, 6, 5 } or { 10, 9, 4, 3 } local ph = p * 1.5708 local legs = { ph, ph + 3.1416, ph + 3.1416, ph } for pass = 1, 2 do for i = 1, 4 do local near = i == 1 or i == 3 if near == (pass == 2) then local fx = anch[i] + floor(amp * sin(legs[i]) + 0.5) local fy = gr - (cos(legs[i]) > 0.3 and 1 or 0) L(g, anch[i], y1 + 1, fx, fy, near and 1 or 2) L(o, anch[i], y1 + 1, fx, fy, 1) P(o, fx + 1, fy, 1) end end if pass == 1 then R(g, x0, y0, x1 - x0 + 1, y1 - y0 + 1, 1) R(g, hx0, hy0, hx1 - hx0 + 1, hy1 - hy0 + 1, 1) if dog then R(g, hx0, hy0, 2, 3, 3); P(g, hx1, hy0 + 2, 4) L(g, x0, y0 + 1, 1, 2, 2, nil) else P(g, hx0, hy0 - 1, 1); P(g, hx1, hy0 - 1, 1); P(g, hx1 - 1, hy0 + 1, 4) for x = 5, 9, 2 do R(g, x, y0, 1, 2, 3) end L(g, x0, y0 + 1, 1, 0, 2, nil) end end end local hcx, hcy = (hx0 + hx1) // 2, (hy0 + hy1) // 2 D(o, hcx, hcy, 2, 1); P(o, hcx + 1, hcy - 1, 0) L(o, x1, y0 + 1, hcx, hcy, 1) L(o, x0 + 1, y0 + 1, x1, y0 + 1, 1) for x = x1 - 2, x0 + 3, -2 do L(o, x, y0 + 1, x, y1, 2) end L(o, x0, y0 + 1, 1, dog and 2 or 0, 2) return { S(g), S(g, true), S(o), S(o, true), g.w, g.h } end local LEGS = { { { 4, 0 }, { -4, 0 } }, { { 0, 0 }, { 1, 3 } }, { { -4, 0 }, { 4, 0 } }, { { 1, 3 }, { 0, 0 } } } local FARARM = { 15, 12, 7, 10 } local NEARARM = { 8, 11, 15, 12 } local function human(k, p) local case = k == 3 local g, o = G(24, 34), G(24, 34) local bob = (p == 0 or p == 2) and 1 or 0 local hy, sy = 21 + bob, 11 + bob local function leg(l, near) local fx, lift = 11 + l[1], l[2] local fy = 33 - lift local kx, ky = (11 + fx) // 2 + (lift > 0 and 3 or 0), (hy + fy) // 2 L(g, 11, hy, kx, ky, near and 5 or 6, true); L(g, kx, ky, fx, fy - 1, near and 5 or 6, true) R(g, fx - 1, fy, 4, 1, 7) L(o, 11, hy, kx, ky, 1); L(o, kx, ky, fx, fy - 1, 1); P(o, fx + 1, fy, 1) end local function arm(hxp, hyp, c) L(g, 11, sy + 1, hxp, hyp, c, true); P(g, hxp, hyp, 1) L(o, 11, sy + 1, hxp, hyp, 1) end leg(LEGS[p + 1][2], false) arm(FARARM[p + 1], hy - 1 + (p % 2), 4) R(g, 8, sy - 1, 7, hy - sy + 2, 4); R(g, 9, sy - 1, 6, hy - sy + 2, 3) R(g, 8, hy - 1, 7, 2, 5) L(g, 11, 9 + bob, 11, 10 + bob, 1) D(g, 12, 6 + bob, 3, 1); R(g, 9, 3 + bob, 6, 2, 2); P(g, 14, 6 + bob, 11) leg(LEGS[p + 1][1], true) if case then local hxp, hyp = 13 + ({ 1, 0, -1, 0 })[p + 1], hy + 1 L(g, 11, sy + 1, hxp, hyp, 3, true); P(g, hxp, hyp, 1) R(g, hxp - 4, hyp + 2, 9, 7, 8); R(g, hxp - 4, hyp + 4, 9, 1, 9); R(g, hxp - 1, hyp + 1, 3, 1, 10) L(o, 11, sy + 1, hxp, hyp, 1) for _, e in ipairs({ { 0, 0, 9, 1 }, { 0, 6, 9, 1 }, { 0, 0, 1, 7 }, { 8, 0, 1, 7 } }) do R(o, hxp - 4 + e[1], hyp + 2 + e[2], e[3], e[4], 2) end for _, e in ipairs({ { -3, 3 }, { -2, 3 }, { -1, 3 }, { -3, 4 }, { -1, 4 }, { -3, 5 }, { -2, 5 }, { -1, 5 }, { -2, 6 }, { -2, 7 }, { -1, 7 }, { 1, 4 }, { 2, 4 }, { 3, 4 }, { 1, 5 }, { 3, 5 }, { 1, 6 }, { 2, 6 }, { 3, 6 }, { 1, 3 }, { 3, 3 } }) do P(o, hxp + e[1], hyp + e[2], 3) end P(o, hxp + 2, hyp + 5, 2) else arm(NEARARM[p + 1], hy - 1 + (p % 2), 3) end D(o, 12, 6 + bob, 3, 1); P(o, 12, 6 + bob, 0); P(o, 14, 6 + bob, 0); R(o, 10, 9 + bob, 4, 1, 2) L(o, 11, 10 + bob, 11, hy, 1) for r = 0, 4, 2 do R(o, 9, sy + r, 5, 1, 2) end R(o, 9, hy - 1, 5, 2, 1); P(o, 11, hy, 0) return { S(g), S(g, true), S(o), S(o, true), 24, 34 } end local SPR = {} local function sprite(k, p) local key = k * 4 + p local s = SPR[key] if not s then s = (k <= 2) and quad(k, p) or human(k, p) SPR[key] = s end return s end local SX0, SY0, SW, SH = 13, 6, 38, 55 local BG, SCREEN = nil, nil local function build_scene() rect(0, 0, W, 60, 118, 146, 150) rect(0, 0, W, 2, 200, 220, 220) rect(2, 0, 7, 2, 255, 255, 240); rect(55, 0, 7, 2, 255, 255, 240) rect(2, 12, 7, 11, 212, 214, 190); rect(3, 14, 5, 1, 120, 140, 130); rect(3, 17, 5, 1, 120, 140, 130) rect(3, 20, 3, 1, 120, 140, 130) rect(55, 6, 9, 54, 84, 104, 108); rect(57, 10, 5, 12, 150, 190, 196); rect(56, 38, 1, 4, 200, 190, 120) rect(0, 44, 11, 1, 170, 190, 190); rect(53, 44, 2, 1, 170, 190, 190) rect(0, 60, W, 4, 74, 94, 98) for x = 0, W, 16 do rect(x, 60, 1, 4, 60, 78, 82) end rect(0, 59, W, 1, 96, 120, 124) rect(11, 4, 42, 59, 52, 64, 68) rect(SX0, SY0, SW, SH, 6, 32, 38) gfx.text(15, 8, "X-RAY", 40, 120, 120, { font = "3x5" }) BG = gfx.snapshot(0, 0, W, H) SCREEN = gfx.snapshot(SX0, SY0, SW, SH) end local ACT = { { 2, -1, 300, 1, 62 }, { 1, 1, 20, 2, 63 }, { 1, -1, 420, 2, 63 }, { 4, -1, 160, 1, 62 }, { 3, 1, 100, 1, 63 }, } local STRIDE = { 6, 3, 5, 5 } local MARGIN, CYC = 20, 540 local VIS = {} function render() if not BG then build_scene() end local who, sp = cfg.who or "all", (cfg.pace == "brisk") and 2 or 1 local tt = (frame * sp) % CYC gfx.blit_rgb(BG, 0, 0, W, H) local n = 0 for i = 1, #ACT do local a = ACT[i] local k, dir, t0, v, base = a[1], a[2], a[3], a[4], a[5] local dt = tt - t0 local show = who == "all" or (who == "animals") == (k <= 2) if show and dt >= 0 and dt * v < W + 2 * MARGIN then local trav = v * dt local x = dir > 0 and (trav - MARGIN) or (W + MARGIN - trav) local s = sprite(k, (trav // STRIDE[k]) % 4) local w, h = s[5], s[6] local xl, yt = x - w // 2, base - h + 1 blit_indexed(s[dir > 0 and 1 or 2], PALS[k], xl, yt, w, h, w, h, true) n = n + 1 VIS[n] = { s[dir > 0 and 3 or 4], xl, yt, w, h } end end gfx.blit_rgb(SCREEN, SX0, SY0, SW, SH) blend_rect(SX0, SY0 + (frame // 2) % SH, SW, 2, 40, 160, 160, 0.16) if (frame // 15) % 2 == 0 then rect(46, 8, 2, 2, 190, 50, 50) end clip(SX0, SY0, SW, SH) for i = 1, n do local v = VIS[i] blit_indexed(v[1], BONE, v[2], v[3], v[4], v[5], v[4], v[5], true) end clip() end