info = { type = "image", title = "Geese by the cottage", category = "animals", author = "BRRRO", version = "1.0", license = "MIT", desc = "Geese waddle past a cottage, one steps out", api = 33, } local tr = ({ sk = { ["Grazing geese"] = "Pasúce sa husi", ["Thatch colour"] = "Farba slamy", ["Chimney smoke"] = "Dym z komína" }, cs = { ["Grazing geese"] = "Pasoucí se husy", ["Thatch colour"] = "Barva došků", ["Chimney smoke"] = "Kouř z komína" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "grazers", label = T("Grazing geese"), type = "int", min = 0, max = 3, default = 2 }, { key = "roof", label = T("Thatch colour"), type = "color", default = "#D8AE48" }, { key = "smoke", label = T("Chimney smoke"), type = "bool", default = true }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, sin, sqrt = math.floor, math.sin, math.sqrt local hash32, umod = math.hash32, math.umod local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local SKY, SKY_LO = { 142, 200, 244 }, { 176, 224, 250 } local SUN, SUN_HALO = { 255, 232, 120 }, { 200, 232, 250 } local HILL = { 104, 182, 110 } local MEAD, MEAD_L = { 72, 160, 64 }, { 108, 192, 82 } local MEAD_D = { 50, 126, 56 } local WALL, WALL_D = { 150, 104, 66 }, { 108, 72, 46 } local PLANK = { 174, 126, 82 } local DOORC, DOOR_D = { 104, 64, 34 }, { 74, 46, 26 } local INSIDE = { 44, 28, 24 } local KNOB = { 246, 206, 90 } local GLASS, FRAME = { 126, 186, 226 }, { 238, 226, 192 } local STONE, STONE_L = { 146, 138, 130 }, { 188, 180, 170 } local FENCE, FENCE_S = { 244, 240, 228 }, { 188, 192, 204 } local RED, PINK, YEL = { 224, 56, 52 }, { 250, 150, 190 }, { 255, 224, 80 } local WHITE = { 246, 246, 240 } local BELLY, WING = { 198, 208, 226 }, { 220, 228, 240 } local ORANGE, EYE = { 244, 146, 30 }, { 30, 30, 40 } local ROOF, ROOF_D = { 216, 174, 72 }, { 176, 134, 50 } local HILL_Y = {} for x = 0, W - 1 do HILL_Y[x] = floor(44 + 2.2 * sin(x * 0.13) + 1.6 * sin(x * 0.31 + 1) + 0.5) end local function c3(c) return c[1], c[2], c[3] end local function disc(cx, cy, r, c) for dy = -r, r do local dx = floor(sqrt(r * r - dy * dy) + 0.5) rect(cx - dx, cy + dy, 2 * dx + 1, 1, c3(c)) end end local function soft(x, y, w, h, r, g, b) local x0 = floor(x) local f = x - x0 if f < 0.05 then rect(x0, y, w, h, r, g, b) return end if f > 0.95 then rect(x0 + 1, y, w, h, r, g, b) return end if w > 1 then rect(x0 + 1, y, w - 1, h, r, g, b) end blend_rect(x0, y, 1, h, r, g, b, 1 - f) blend_rect(x0 + w, y, 1, h, r, g, b, f) end local BG = nil local function build_bg() local rc = cfg.roof or { r = 216, g = 174, b = 72 } ROOF[1], ROOF[2], ROOF[3] = rc.r, rc.g, rc.b ROOF_D[1], ROOF_D[2], ROOF_D[3] = rc.r * 8 // 10, rc.g * 8 // 10, rc.b * 7 // 10 rect(0, 0, W, H, c3(SKY)) rect(0, 36, W, 14, c3(SKY_LO)) for x = 0, W - 1, 2 do px(x, 35, c3(SKY_LO)) end disc(54, 9, 7, SUN_HALO) disc(54, 9, 4, SUN) for x = 0, W - 1, 2 do local hy = HILL_Y[x] rect(x, hy, 2, 50 - hy, c3(HILL)) end rect(0, 49, W, H - 49, c3(MEAD)) for i = 1, 26 do local h = hash32(i * 0x9E3779B1) local x, y = umod(h, W - 2), 52 + umod(h >> 8, 11) local c = (h >> 20) & 1 == 1 and MEAD_L or MEAD_D rect(x, y, 2, 1, c3(c)); px(x + 1, y - 1, c3(c)) end rect(36, 45, 28, 1, c3(FENCE)); rect(36, 48, 28, 1, c3(FENCE)) for x = 38, 62, 6 do rect(x, 43, 2, 7, c3(FENCE)); px(x, 42, c3(FENCE)) rect(x + 1, 44, 1, 6, c3(FENCE_S)) end rect(22, 12, 4, 13, c3(STONE)); rect(21, 10, 6, 2, c3(STONE_L)) for y = 15, 30 do local half = (y - 15) * 17 // 15 local c = (y % 3 == 0) and ROOF_D or ROOF rect(17 - half, y, 2 * half + 2, 1, c3(c)) end rect(2, 31, 32, 19, c3(WALL)) rect(2, 31, 32, 1, c3(WALL_D)) for y = 33, 48, 3 do rect(4, y, 28, 1, c3(PLANK)) end rect(2, 31, 2, 19, c3(WALL_D)); rect(32, 31, 2, 19, c3(WALL_D)) rect(2, 49, 32, 2, c3(STONE)) rect(6, 35, 9, 8, c3(FRAME)) rect(7, 36, 3, 3, c3(GLASS)); rect(11, 36, 3, 3, c3(GLASS)) rect(7, 40, 3, 2, c3(GLASS)); rect(11, 40, 3, 2, c3(GLASS)) rect(5, 43, 11, 1, c3(STONE_L)) rect(6, 44, 9, 2, c3(WALL_D)) px(7, 43, c3(RED)); px(9, 43, c3(PINK)); px(11, 43, c3(RED)); px(13, 43, c3(YEL)) rect(18, 36, 12, 13, c3(DOORC)) for x = 21, 27, 3 do rect(x, 36, 1, 13, c3(DOOR_D)) end px(28, 43, c3(KNOB)) rect(17, 49, 14, 1, c3(STONE_L)) px(31, 48, c3(YEL)); px(33, 47, c3(PINK)); px(35, 48, c3(RED)); px(15, 48, c3(PINK)) BG = gfx.snapshot(0, 0, W, H) end local gx, gy, gd, gsoft = 0, 0, 1, false local function P(ox, oy, w, h, c) local left = gd > 0 and gx + ox or gx - ox - w + 1 if gsoft then soft(left, gy + oy, w, h, c[1], c[2], c[3]) else rect(floor(left + 0.5), gy + oy, w, h, c[1], c[2], c[3]) end end local function draw_goose(x, yb, dir, mode, k) gx, gy, gd, gsoft = x, yb, dir, mode == 0 blend_rect(floor(x + 0.5) - 6, yb, 13, 1, 20, 70, 30, 0.35) if mode == 0 and k == 1 then P(-2, -3, 1, 2, ORANGE); P(2, -3, 1, 3, ORANGE); P(2, -1, 2, 1, ORANGE) elseif mode == 0 then P(-2, -3, 1, 3, ORANGE); P(-2, -1, 2, 1, ORANGE); P(2, -3, 1, 2, ORANGE) else P(-2, -3, 1, 3, ORANGE); P(-2, -1, 2, 1, ORANGE) P(2, -3, 1, 3, ORANGE); P(2, -1, 2, 1, ORANGE) end P(-3, -8, 7, 1, WHITE); P(-5, -7, 11, 2, WHITE); P(-4, -5, 9, 1, WHITE) P(-3, -4, 7, 1, BELLY); P(-6, -8, 1, 2, WHITE) P(-4, -7, 6, 2, WING); P(-6, -6, 2, 1, WING) if mode == 2 then P(5, -9, 2, 5, WHITE) P(6, -5 + k, 3, 2, WHITE); P(9, -4 + k, 2, 1, ORANGE); P(7, -5 + k, 1, 1, EYE) else local hx = 4 + (mode == 0 and k or 0) P(4, -11, 2, 4, WHITE) P(hx, -13, 3, 2, WHITE); P(hx + 3, -12, 2, 1, ORANGE); P(hx + 1, -13, 1, 1, EYE) end end local GZ = { { 48, 53, -1 }, { 10, 62, 1 }, { 58, 61, -1 } } local EX, EY, ED, EM, EK, EC = {}, {}, {}, {}, {}, {} local NE = 0 local function add(x, y, d, m, k, clipped) local i = NE + 1 while i > 1 and EY[i - 1] > y do EX[i], EY[i], ED[i], EM[i], EK[i], EC[i] = EX[i - 1], EY[i - 1], ED[i - 1], EM[i - 1], EK[i - 1], EC[i - 1] i = i - 1 end EX[i], EY[i], ED[i], EM[i], EK[i], EC[i] = x, y, d, m, k, clipped NE = NE + 1 end local CLOUDS = { { 8, 16, 1.6, 6 }, { 22, 12, -1.0, 40 } } function on_settings() BG = nil end function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local t = frame * STEP_HZ // FPS for i = 1, #CLOUDS do local c = CLOUDS[i] local y, L = c[1], c[2] local x = floor((c[4] + t * c[3] / STEP_HZ) % (W + L) - L + 0.5) blend_rect(x + 3, y, L - 6, 1, 255, 255, 255, 0.8) blend_rect(x, y + 1, L, 2, 255, 255, 255, 0.8) blend_rect(x + 2, y + 3, L - 6, 1, 255, 255, 255, 0.6) end if cfg.smoke ~= false then for k = 0, 4 do local u = (t / (1.4 * STEP_HZ) + k / 5) % 1 local x = 23 + u * 9 + sin(u * 6 + k) * 1.2 local y = 9 - u * 9 local s = u > 0.45 and 3 or 2 blend_rect(floor(x), floor(y), s, 2, 240, 240, 244, 0.75 * (1 - u)) end end local sA = (t + 10) % 420 - 10 local xA = -2 + 0.28 * sA if sA <= 125 then rect(18, 36, 12, 13, c3(INSIDE)) rect(15, 36, 3, 13, c3(DOORC)); rect(15, 36, 1, 13, c3(DOOR_D)) end NE = 0 local step = (t // 6) % 2 if sA >= 0 and xA < 76 then local yA = 50 + floor(math.min(5, math.max(0, (xA - 34) * 0.5))) add(xA, yA, 1, 0, step, xA < 36) end local xB = 84 - 0.2 * ((t + 200) % 640) if xB > -14 then add(xB, 58, -1, 0, (t // 8) % 2, false) end for i = 1, cfg.grazers or 2 do local g = GZ[i] local tt = (t + i * 47) % 180 if tt < 110 then add(g[1], g[2], g[3], 2, (tt // 9) % 2, false) else add(g[1], g[2], g[3], 1, 0, false) end end for i = 1, NE do if EC[i] then gfx.clip(18, 0, 46, H) end draw_goose(EX[i], EY[i], ED[i], EM[i], EK[i]) if EC[i] then gfx.clip() end end end