info = { type = "image", title = "White cat walk", category = "animals", author = "BRRRO", version = "1.0", license = "MIT", desc = "A white cat strolls past a garden fence", api = 33, } local tr = ({ sk = { ["Stops to look around"] = "Zastaví sa a obzrie" }, cs = { ["Stops to look around"] = "Zastaví se a rozhlédne" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "stops", label = T("Stops to look around"), type = "bool", default = true }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, sin = math.floor, math.sin local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local CX, CY = 16, 26 local OUT = { 88, 92, 112 } local WH = { 244, 244, 250 } local SH = { 196, 202, 222 } local PINK = { 238, 148, 170 } local EYE = { 36, 40, 58 } local function art(rows, keys) local map, w = { ["."] = "\0" }, #rows[1] for i = 1, #keys do map[keys:sub(i, i)] = string.char(i) end local t = {} for i = 1, #rows do assert(#rows[i] == w, "riadok " .. i) t[i] = rows[i]:gsub(".", map) end return table.concat(t), w, #rows end local BODY, BW, BH = art({ "...................o......o...", "..................opo....opo..", ".................owpwoooowpwo.", "................owwwwwwwwwwwwo", "................owwwwwwwwwwwwo", "................owwwwwwwwwwwwo", ".....oooooooooooowwwwwwwwwwwwo", "...oowwwwwwwwwwwwwwwwwwwwwwwwo", "..owwwwwwwwwwwwwwwwwwwwwwwwwo.", ".owwwwwwwwwwwwwwwwwwwwwwwwwo..", ".owwwwwwwwwwwwwwwwwwwwwwwwo...", ".owwwwwwwwwwwwwwwwwwwwwwwo....", ".osswwwwwwwwwwwwwwwwwwwso.....", "..ossswwwwwwwwwwwwwwwsso......", "...osssssssssssssssssso.......", "....oooooooooooooooooo........", }, "owsp") local BPAL = { 0, 0, 0, OUT[1], OUT[2], OUT[3], WH[1], WH[2], WH[3], SH[1], SH[2], SH[3], PINK[1], PINK[2], PINK[3] } local TOP, TILE = nil, nil local SKY = { 116, 176, 224 } local CLOUD = { 210, 228, 244 } local BOARD = { 156, 100, 60 } local BOARD_L = { 188, 130, 82 } local BOARD_D = { 120, 74, 44 } local GAP = { 66, 42, 30 } local RAIL = { 128, 80, 46 } local BUSH = { 46, 112, 54 } local BUSH_L = { 74, 146, 66 } local GRASS = { 98, 168, 70 } local GRASS_D = { 78, 146, 60 } local TUFT = { 136, 200, 96 } local FLOWERS = { { 232, 62, 74 }, { 250, 206, 52 }, { 236, 120, 196 }, { 255, 150, 40 } } local function c3(c) return c[1], c[2], c[3] end local function build_bg() rect(0, 0, W, H, c3(SKY)) rect(6, 3, 14, 3, c3(CLOUD)); rect(8, 2, 8, 1, c3(CLOUD)); rect(9, 6, 9, 1, c3(CLOUD)) rect(40, 5, 12, 2, c3(CLOUD)); rect(42, 4, 6, 1, c3(CLOUD)) TOP = gfx.snapshot(0, 0, W, 10) rect(0, 13, W, 33, c3(GAP)) for b = 0, 7 do local x = b * 8 rect(x, 13, 7, 30, c3(BOARD)) rect(x + 1, 12, 5, 1, c3(BOARD)); rect(x + 2, 11, 3, 1, c3(BOARD)); px(x + 3, 10, c3(BOARD)) rect(x, 13, 1, 30, c3(BOARD_L)) rect(x + 6, 13, 1, 30, c3(BOARD_D)) local h = hash32(b * 0x9E3779B1) rect(x + 2 + umod(h, 3), 24 + umod(h >> 4, 6), 1, 3, c3(BOARD_D)) rect(x + 3 + umod(h >> 8, 2), 38 + umod(h >> 12, 3), 1, 2, c3(BOARD_D)) end for _, y in ipairs({ 18, 33 }) do rect(0, y, W, 3, c3(RAIL)) rect(0, y, W, 1, c3(BOARD)) for b = 0, 7 do px(b * 8 + 3, y + 1, c3(GAP)) end end for x = 0, W - 1 do local h = hash32((x // 3) * 0x85EBCA6B) local top = 38 + umod(h, 3) + floor(1.5 * sin(x * 0.4) + 0.5) rect(x, top, 1, 46 - top, c3(BUSH)) if umod(h >> 5, 4) == 0 then px(x, top + 1, c3(BUSH_L)) end end for i = 0, 6 do local h = hash32(i * 0xC2B2AE35 + 7) local x, y = i * 9 + 2 + umod(h, 4), 39 + umod(h >> 4, 4) local c = FLOWERS[umod(h >> 8, #FLOWERS) + 1] rect(x - 1, y, 3, 1, c3(c)); rect(x, y - 1, 1, 3, c3(c)) px(x, y, 255, 236, 140) end rect(0, 46, W, 18, c3(GRASS)) rect(0, 56, W, 8, c3(GRASS_D)) for x = 0, W - 1, 2 do px(x, 55, c3(GRASS_D)) end for i = 0, 13 do local h = hash32(i * 0x27D4EB2F + 3) local x, y = umod(h, W), 47 + umod(h >> 8, 15) px(x, y, c3(TUFT)); px(x + 1, y - 1, c3(TUFT)) end TILE = gfx.snapshot(0, 10, W, H - 10) end local STRIDE, WALK, STOP = 10, 220, 80 local LEGS = { { 7, 0.50, false }, { 21, 0.75, false }, { 4, 0.00, true }, { 18, 0.25, true }, } local function leg(hx, q, near, stopped) local s, lift if q < 0.6 then s, lift = 3 - 6 * q / 0.6, 0 else local u = (q - 0.6) / 0.4 s, lift = -3 + 6 * u, (u > 0.2 and u < 0.8) and 1 or 0 end if stopped then lift = 0; if q >= 0.6 then s = 0 end end local su, sl = floor(s * 0.4 + 0.5), floor(s + 0.5) local x = CX + hx + (near and 0 or 1) local col = near and WH or SH local yb = CY + 20 - lift rect(x + su, CY + 15, 4, 2, c3(OUT)); rect(x + su + 1, CY + 15, 2, 2, c3(col)) rect(x + sl, CY + 17, 4, yb - CY - 16, c3(OUT)) rect(x + sl + 1, CY + 17, 2, yb - CY - 17, c3(col)) end local function tail(t, amp, per) local sw = amp * sin(t * 6.28318 / per) local bx, by = CX + 2, CY + 8 local xt for k = 0, 10 do local f = k / 10 local x = floor(bx - 0.45 * k + sw * f * f + 0.5) rect(x - 1, by - k, 4, 1, c3(OUT)) if k < 10 then rect(x, by - k, 2, 1, c3(WH)) end xt = x end rect(xt, by - 11, 2, 1, c3(OUT)) end local EYES = { [0] = { 21, 26, 23 }, { 20, 25, 22 }, { 18, 23, 20 } } local function face(look, blink) local e = EYES[look] rect(CX + 17, CY + 5, 12, 3, c3(WH)) if blink then rect(CX + e[1], CY + 6, 1, 1, c3(OUT)); rect(CX + e[2], CY + 6, 1, 1, c3(OUT)) else rect(CX + e[1], CY + 5, 1, 2, c3(EYE)); rect(CX + e[2], CY + 5, 1, 2, c3(EYE)) end rect(CX + e[3], CY + 7, 2, 1, c3(PINK)) px(CX + e[1] - 1, CY + 7, 250, 206, 214); px(CX + e[2] + 1, CY + 7, 250, 206, 214) end function render() if not TILE then build_bg() end local t = frame * STEP_HZ // FPS local stops = cfg.stops ~= false local dist, ph, stopped = t, 0, false if stops then local n = t // (WALK + STOP) ph = t - n * (WALK + STOP) stopped = ph >= WALK dist = n * WALK + (stopped and WALK or ph) end local s = dist % W gfx.blit_rgb(TILE, -s, 10, W, H - 10) gfx.blit_rgb(TILE, W - s, 10, W, H - 10) gfx.blit_rgb(TOP, 0, 0, W, 10) blend_rect(CX + 3, CY + 21, 24, 2, 30, 70, 30, 0.35) local look, blink = 0, (t % 120) < 3 local amp, per = 1.5, 30 if stopped then local f = ph - WALK if f >= 10 and f < 14 then look = 1 elseif f >= 14 and f < 40 then look = 2 elseif f >= 40 and f < 62 then look = 1 end blink = (f >= 50 and f < 53) or (f >= 70 and f < 73) amp, per = 3, 48 end local q0 = dist / STRIDE for i = 1, 2 do local L = LEGS[i]; leg(L[1], (q0 + L[2]) % 1, false, stopped) end tail(t, amp, per) gfx.blit_indexed(BODY, BPAL, CX, CY, BW, BH, BW, BH, true) for i = 3, 4 do local L = LEGS[i]; leg(L[1], (q0 + L[2]) % 1, true, stopped) end face(look, blink) end