info = { type = "image", title = "Kennel woof", category = "animals", author = "BRRRO", version = "1.0", license = "MIT", desc = "Dog peeking from a kennel, barking, hat jumps", api = 33, } local ltr = ({ sk = { ["Hat"] = "Klobúk", ["Barking"] = "Šteká", ["Often"] = "Často", ["Normal"] = "Bežne", ["Rarely"] = "Zriedka" }, cs = { ["Hat"] = "Klobouk", ["Barking"] = "Štěká", ["Often"] = "Často", ["Normal"] = "Běžně", ["Rarely"] = "Zřídka" }, })[lang] or {} local function LT(s) return ltr[s] or s end settings = { { key = "hat", label = LT("Hat"), type = "color", default = "#B428DC" }, { key = "bark", label = LT("Barking"), type = "int", default = "normal", opts = { keys = { "often", "normal", "rare" }, LT("Often"), LT("Normal"), LT("Rarely") } }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local blit_rgb, snapshot = gfx.blit_rgb, gfx.snapshot 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 SKY1, SKY2, SKY3 = { 118, 190, 236 }, { 136, 204, 242 }, { 156, 216, 246 } local ROOF, ROOF_D, ROOF_L = { 160, 56, 44 }, { 124, 40, 38 }, { 204, 92, 64 } local WALL, WALL_D, FRAME = { 222, 152, 92 }, { 188, 116, 68 }, { 248, 216, 152 } local DARK, SILL = { 44, 28, 36 }, { 134, 86, 52 } local GRASS, GRASS_D, GRASS_L = { 96, 176, 72 }, { 72, 152, 62 }, { 138, 204, 96 } local EAR, EAR_D, WHITE, WHITE_D, INK = { 194, 136, 100 }, { 160, 102, 74 }, { 250, 248, 242 }, { 226, 222, 218 }, { 38, 28, 34 } local BUBBLE_FILL, BUBBLE_EDGE, BUBBLE_TXT = { 252, 252, 255 }, { 52, 40, 70 }, { 46, 32, 70 } local function c3(c) return c[1], c[2], c[3] end local BG = nil local function build_bg() rect(0, 0, W, 18, c3(SKY1)) rect(0, 18, W, 18, c3(SKY2)) rect(0, 36, W, 16, c3(SKY3)) for y = 2, 14 do for x = 3, 15 do local d = sqrt((x - 9) ^ 2 + (y - 8) ^ 2) if d <= 4.3 then px(x, y, 255, 226, 80) elseif d <= 5.3 then px(x, y, 255, 240, 160) end end end for x = 0, 33 do local y = floor(47 + 2 * sin(x * 0.19 + 0.5) + 1.2 * sin(x * 0.47) + 0.5) rect(x, y, 1, 52 - y, 126, 200, 118) end rect(0, 52, W, 12, c3(GRASS)) rect(0, 58, W, 6, c3(GRASS_D)) for i = 1, 26 do local h = hash32(i * 0x9E3779B1 + 3) local x, y = umod(h, W), 53 + umod(h >> 8, 10) px(x, y, c3(GRASS_L)) if i % 3 == 0 then px(x + 1, y - 1, 255, 226, 110) end end for y = 8, 21 do local hw = 1 + (y - 8) * 3 // 2 rect(50 - hw, y, 2 * hw, 1, c3((y - 8) % 3 == 2 and ROOF_D or ROOF)) px(50 - hw, y, c3(ROOF_L)) end rect(30, 22, 34, 30, c3(WALL)) rect(30, 22, 34, 2, c3(WALL_D)) rect(34, 24, 1, 28, c3(WALL_D)) rect(62, 24, 1, 28, c3(WALL_D)) local ARCH = { 44, 42, 41, 40 } for i = 0, 26 do local l = ARCH[i + 1] or 39 rect(l - 1, 24 + i, 2 * (50 - l) + 2, 1, c3(FRAME)) end for i = 0, 26 do local l = ARCH[i + 1] or 39 rect(l, 25 + i, 2 * (50 - l), 1, c3(DARK)) end rect(36, 52, 28, 1, c3(FRAME)) rect(36, 53, 28, 1, c3(SILL)) rect(6, 56, 10, 1, 150, 96, 60) rect(6, 57, 10, 1, 230, 100, 90) rect(7, 58, 8, 1, 200, 60, 60) rect(8, 59, 6, 1, 170, 44, 50) rect(23, 60, 5, 1, 250, 246, 230) rect(22, 59, 1, 3, 250, 246, 230) rect(28, 59, 1, 3, 250, 246, 230) BG = snapshot(0, 0, W, H) end local MARG, PC = 30, W + 60 local CLOUDS = { { y = 4, v = 1.4, x0 = 40, rows = { { 6, 14 }, { 3, 18 }, { 0, 21 } } }, { y = 16, v = 0.9, x0 = 100, rows = { { 4, 9 }, { 1, 12 }, { 0, 13 } } }, } local function frow(xl, xr, y, r, g, b) local il, ir = floor(xl), floor(xr) if ir <= il then return end rect(il + 1, y, ir - il - 1, 1, r, g, b) blend_rect(il, y, 1, 1, r, g, b, 1 - (xl - il)) blend_rect(ir, y, 1, 1, r, g, b, xr - ir) end local CYCLE = 270 local HAT, HAT_D, HAT_L = { 180, 40, 220 }, { 126, 28, 154 }, { 214, 130, 240 } local TXT_Y, TXT_OPTS local function light(c, k) return floor(c + (255 - c) * k) end function on_settings() local c = cfg.hat or { r = 180, g = 40, b = 220 } HAT, HAT_D = { c.r, c.g, c.b }, { c.r * 7 // 10, c.g * 7 // 10, c.b * 7 // 10 } HAT_L = { light(c.r, 0.45), light(c.g, 0.45), light(c.b, 0.45) } CYCLE = ({ often = 210, normal = 270, rare = 450 })[cfg.bark] or 270 end local function ease_out(u) return 1 - (1 - u) ^ 3 end local function head_dy(f) if f < 15 then return 18 end if f < 36 then return floor(18 * (1 - ease_out((f - 15) / 21)) + 0.5) end if f < 66 then return 0 end if f < 70 then return -1 end if f < 88 then return 0 end if f < 92 then return 1 end if f < 170 then return 0 end if f < 190 then return floor(18 * ((f - 170) / 20) ^ 2 + 0.5) end return 18 end local function draw_dog(f, dy) local y0 = 36 + dy local open = f >= 66 and f < 92 local squint = open or (f >= 52 and f < 55) or (f >= 122 and f < 125) local ear = (f >= 88 and f < 96) and 1 or 0 gfx.clip(39, 25, 22, 27) rect(41, y0 + 1 + ear, 4, 12, c3(EAR)) rect(41, y0 + 1 + ear, 1, 12, c3(EAR_D)) rect(55, y0 + 1 + ear, 4, 12, c3(EAR)) rect(58, y0 + 1 + ear, 1, 12, c3(EAR_D)) rect(45, y0, 10, 14, c3(WHITE)) rect(45, y0, 1, 14, c3(WHITE_D)) rect(54, y0, 1, 14, c3(WHITE_D)) rect(45, y0 + 1, 3, 5, c3(EAR)) if squint then rect(46, y0 + 6, 2, 1, c3(INK)) rect(52, y0 + 6, 2, 1, c3(INK)) else rect(46, y0 + 5, 2, 2, c3(INK)) rect(52, y0 + 5, 2, 2, c3(INK)) end rect(48, y0 + 8, 4, 2, c3(INK)) if open then rect(47, y0 + 10, 6, 3, 60, 24, 40) rect(49, y0 + 12, 2, 1, 236, 96, 120) else rect(49, y0 + 10, 2, 1, c3(INK)) rect(47, y0 + 11, 6, 1, 150, 120, 116) end rect(46, y0 + 14, 8, 1, 210, 50, 70) rect(46, y0 + 15, 8, 3, c3(WHITE)) rect(49, y0 + 15, 2, 1, 255, 214, 70) return y0 end local function draw_hat(hy) rect(44, hy, 12, 6, c3(HAT)) rect(44, hy + 4, 12, 1, c3(HAT_D)) rect(45, hy + 1, 1, 3, c3(HAT_L)) rect(42, hy + 6, 16, 2, c3(HAT)) rect(42, hy + 7, 16, 1, c3(HAT_D)) end local function draw_bubble() gfx.round_rect(1, 31, 29, 17, BUBBLE_FILL[1], BUBBLE_FILL[2], BUBBLE_FILL[3], BUBBLE_EDGE[1], BUBBLE_EDGE[2], BUBBLE_EDGE[3], 3) local xe = { 30, 31, 32, 33, 32, 31, 30 } for i = 1, 7 do rect(29, 39 + i, xe[i] - 28, 1, c3(BUBBLE_EDGE)) if i >= 2 and i <= 6 then rect(29, 39 + i, xe[i] - 29, 1, c3(BUBBLE_FILL)) end end if not TXT_Y then TXT_OPTS = { font = "5x7", w = 27, align = "center" } local top, bot = gfx.text_ink("WOOF", TXT_OPTS) TXT_Y = 32 + (15 - (bot - top + 1)) // 2 - top end gfx.text(2, TXT_Y, "WOOF", BUBBLE_TXT[1], BUBBLE_TXT[2], BUBBLE_TXT[3], TXT_OPTS) end function render() if not BG then build_bg() end blit_rgb(BG, 0, 0, W, H) local t = frame / FPS for i = 1, #CLOUDS do local c = CLOUDS[i] local x = (c.x0 + t * c.v) % PC - MARG for r = 1, 3 do local w = c.rows[r] if r == 3 then frow(x + w[1], x + w[2], c.y + r - 1, 214, 230, 244) else frow(x + w[1], x + w[2], c.y + r - 1, 252, 253, 255) end end end local f = frame % CYCLE local dy = head_dy(f) if dy >= 18 then local lid = (f % 55) < 3 rect(45, lid and 45 or 44, 2, lid and 1 or 2, 240, 232, 170) rect(52, lid and 45 or 44, 2, lid and 1 or 2, 240, 232, 170) return end local y0 = draw_dog(f, dy) local hy = y0 - 8 local flying = f >= 66 and f < 88 if flying then local u = (f - 66) / 22 hy = 28 + dy - floor(17 * 4 * u * (1 - u) + 0.5) gfx.clip() end draw_hat(hy) gfx.clip() if f >= 66 and f < 112 then draw_bubble() end end