info = { type = "image", title = "Waiting dog", category = "animals", author = "BRRRO", version = "1.0", license = "MIT", desc = "A dog sits and waits, wags its tail", api = 33, } local tr = ({ sk = { ["Breed"] = "Plemeno", ["Golden"] = "Zlatý", ["Beagle"] = "Bígl", ["Husky"] = "Husky", ["Chocolate"] = "Čokoládový", ["Bone"] = "Kosť" }, cs = { ["Breed"] = "Plemeno", ["Golden"] = "Zlatý", ["Beagle"] = "Bígl", ["Husky"] = "Husky", ["Chocolate"] = "Čokoládový", ["Bone"] = "Kost" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "breed", label = T("Breed"), type = "int", default = "golden", opts = { keys = { "golden", "beagle", "husky", "choc" }, T("Golden"), T("Beagle"), T("Husky"), T("Chocolate") } }, { key = "bone", label = T("Bone"), type = "bool", default = true }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, sin, cos, min, max = math.floor, math.sin, math.cos, math.min, math.max local hash32, umod = math.hash32, math.umod local W, H = gfx.W, gfx.H local CX = 29 local CYC = 600 local WAGS = { { 30, 150 }, { 330, 400 } } local OMEGA = 6.2831853 * 1.8 / 30 local LAG = 0.55 local BREEDS = { golden = { c = { 216, 152, 66 }, s = { 168, 104, 40 }, l = { 246, 206, 132 }, e = { 176, 110, 44 } }, beagle = { c = { 200, 128, 58 }, s = { 146, 90, 40 }, l = { 250, 246, 238 }, e = { 112, 64, 30 }, cap = { 122, 72, 34 } }, husky = { c = { 132, 140, 154 }, s = { 92, 98, 112 }, l = { 244, 246, 250 }, e = { 104, 110, 124 }, cap = { 78, 84, 98 }, cheek = { 244, 246, 250 }, prick = true, blue = true }, choc = { c = { 124, 78, 46 }, s = { 88, 52, 30 }, l = { 178, 128, 84 }, e = { 96, 58, 34 } }, } local B, BG = BREEDS.golden, nil local DK = { 0, 0, 0 } local INK, MOUTH, PINK = { 32, 24, 26 }, { 52, 36, 36 }, { 236, 104, 128 } local DUST = { 232, 220, 196 } local function R(x, y, w, h, c) rect(x, y, w, h, c[1], c[2], c[3]) end local function M(x, y, w, h, c) R(x, y, w, h, c); R(59 - x - w, y, w, h, c) end function on_settings() B = BREEDS[cfg.breed] or BREEDS.golden DK = { B.s[1] * 6 // 10, B.s[2] * 6 // 10, B.s[3] * 6 // 10 } BG = nil end local function bake() for y = 0, 45 do local t = y / 45 rect(0, y, W, 1, floor(136 + 78 * t), floor(194 + 42 * t), floor(246 + 6 * t)) end for x = 1, 63, 5 do rect(x, 36, 4, 10, 168, 128, 84) rect(x, 36, 1, 10, 190, 150, 102) rect(x + 1, 35, 2, 1, 168, 128, 84) end rect(0, 39, W, 1, 138, 100, 64) rect(0, 43, W, 1, 138, 100, 64) for y = 46, H - 1 do local t = (y - 46) / 17 rect(0, y, W, 1, floor(116 - 52 * t), floor(178 - 42 * t), floor(86 - 28 * t)) end for i = 1, 44 do local h = hash32(i * 0x9E3779B1) local x, y = umod(h, W), 47 + umod(h >> 8, 16) if (h >> 20) & 1 == 1 then rect(x, y, 1, 2, 52, 118, 50) else rect(x, y, 1, 2, 146, 200, 104) end end blend_rect(13, 56, 34, 3, 20, 40, 20, 0.35) blend_rect(16, 59, 28, 1, 20, 40, 20, 0.25) if cfg.bone ~= false then local bn, bs = { 244, 234, 208 }, { 204, 188, 150 } R(9, 60, 10, 3, bn); R(9, 62, 10, 1, bs) for _, x in ipairs({ 7, 19 }) do R(x, 59, 2, 2, bn); R(x, 62, 2, 2, bn) R(x, 63, 2, 1, bs) end end local c, s, l = B.c, B.s, B.l M(15, 42, 8, 13, c); M(14, 45, 1, 8, s); M(16, 41, 5, 1, c) M(14, 55, 8, 3, l); M(17, 56, 1, 2, s); M(19, 56, 1, 2, s) R(22, 26, 15, 5, c) R(20, 30, 19, 12, c) R(24, 30, 11, 9, l); R(25, 39, 9, 2, l); R(27, 41, 5, 1, l) R(27, 42, 5, 13, DK) M(22, 41, 5, 14, c); M(26, 41, 1, 14, s) R(31, 54, 7, 4, l); px(33, 56, s[1], s[2], s[3]); px(33, 57, s[1], s[2], s[3]) px(35, 56, s[1], s[2], s[3]); px(35, 57, s[1], s[2], s[3]) rect(22, 30, 15, 2, 206, 52, 60) rect(28, 32, 2, 2, 250, 204, 70) BG = gfx.snapshot(0, 0, W, H) end local function pulse(u, a, b, r) if u <= a or u >= b then return 0 end local k = min((u - a) / r, (b - u) / r, 1) return k * k * (3 - 2 * k) end local function wag_env(u) local e = 0 for i = 1, #WAGS do e = max(e, pulse(u, WAGS[i][1], WAGS[i][2], 10)) end return e end local REST, LEN = { -35, -18, 2 }, { 5.0, 5.0, 4.5 } local function tail(env, ph, idle) local x, y = 44.0, 51.0 for i = 1, 3 do local th = (REST[i] + idle + env * 38 * (1 + sin(ph - (i - 1) * LAG))) * 0.0174533 local ca, sa = cos(th), -sin(th) for j = 1, 4 do local qx, qy = x + ca * LEN[i] * j / 4, y + sa * LEN[i] * j / 4 local c = (i == 3 and j > 1) and B.l or B.c local d = i == 3 and 2 or 3 rect(floor(qx + 0.5) - 1, min(floor(qy + 0.5) - 1, 57 - d + 1), d, d, c[1], c[2], c[3]) end x, y = x + ca * LEN[i], y + sa * LEN[i] end return x, y end local function dust(u, tx) local k = floor((OMEGA * u - 2 * LAG + 1.5708) / 6.2831853) local ui = (6.2831853 * k - 1.5708 + 2 * LAG) / OMEGA local age = u - ui if ui < 0 or age >= 14 or wag_env(ui) < 0.6 then return end for i = 0, 4 do local px_ = tx + (i - 2) * (1.4 + age * 0.4) local py_ = 55 - age * 0.25 - (i % 2) blend_rect(floor(px_ + 0.5), floor(py_ + 0.5), age < 6 and 3 or 4, 3, DUST[1], DUST[2], DUST[3], 0.85 * (1 - age / 14)) end end local function ear(side, dx, dy) local e, s = B.e, B.s if B.prick then local function row(y, a, b) local x1, x2 = CX + a, CX + b if side > 0 then x1, x2 = CX - b, CX - a end rect(x1 + dx, y + dy, x2 - x1 + 1, 1, e[1], e[2], e[3]) end row(1, -9, -8); row(2, -10, -7); row(3, -11, -6); row(4, -11, -5); row(5, -12, -4) for y = 6, 9 do row(y, -12, -3) end row(10, -12, -11) local ix = side < 0 and CX - 10 or CX + 5 rect(ix + dx, 5 + dy, 5, 4, 240, 176, 176) rect(ix + 1 + dx, 4 + dy, 3, 1, 240, 176, 176) return end local ex = side < 0 and (CX - 15) or (CX + 11) rect(ex + dx, 11 + dy, 5, 13, e[1], e[2], e[3]) rect(ex + 1 + dx, 10 + dy, 3, 1, e[1], e[2], e[3]) rect(ex + 1 + dx, 24 + dy, 3, 1, e[1], e[2], e[3]) local ox = side < 0 and ex or ex + 4 rect(ox + dx, 13 + dy, 1, 10, s[1], s[2], s[3]) end local function head(tilt, tl, shut, fl, fr) local c, l = B.c, B.l local cheek = B.cheek or c local sh = tilt >= 0 and floor(tilt + 0.5) or -floor(-tilt + 0.5) local dT, dM = sh * 2, sh ear(-1, dT - fl, -sh - fl * 2) ear(1, dT + fr, sh - fr * 2) rect(CX - 6 + dT, 8, 13, 1, c[1], c[2], c[3]) rect(CX - 8 + dT, 9, 17, 1, c[1], c[2], c[3]) rect(CX - 10 + dT, 10, 21, 4, c[1], c[2], c[3]) rect(CX - 11 + dM, 14, 23, 9, c[1], c[2], c[3]) rect(CX - 10, 23, 21, 3, cheek[1], cheek[2], cheek[3]) rect(CX - 8, 26, 17, 3, cheek[1], cheek[2], cheek[3]) rect(CX - 5, 29, 11, 1, cheek[1], cheek[2], cheek[3]) local p = B.cap if p then rect(CX - 6 + dT, 8, 13, 1, p[1], p[2], p[3]) rect(CX - 8 + dT, 9, 17, 1, p[1], p[2], p[3]) rect(CX - 10 + dT, 10, 21, 3, p[1], p[2], p[3]) end rect(CX - 3 + dM, 16, 7, 7, l[1], l[2], l[3]) rect(CX - 6, 23, 13, 3, l[1], l[2], l[3]) rect(CX - 5, 26, 11, 3, l[1], l[2], l[3]) rect(CX - 3, 29, 7, 1, l[1], l[2], l[3]) rect(CX - 2 + dM, 21, 5, 1, INK[1], INK[2], INK[3]) rect(CX - 1 + dM, 22, 3, 1, INK[1], INK[2], INK[3]) px(CX - 1 + dM, 21, 150, 140, 140) px(CX, 23, MOUTH[1], MOUTH[2], MOUTH[3]); px(CX, 24, MOUTH[1], MOUTH[2], MOUTH[3]) rect(CX - 4, 25, 4, 1, MOUTH[1], MOUTH[2], MOUTH[3]); rect(CX + 1, 25, 4, 1, MOUTH[1], MOUTH[2], MOUTH[3]) px(CX - 5, 24, MOUTH[1], MOUTH[2], MOUTH[3]); px(CX + 5, 24, MOUTH[1], MOUTH[2], MOUTH[3]) if tl > 0 then rect(CX - 1, 26, 3, tl, PINK[1], PINK[2], PINK[3]) end for side = -1, 1, 2 do local x = side < 0 and CX - 8 + dM or CX + 6 + dM local y = 15 + (side < 0 and -sh or sh) local s = B.s rect(x, y - 3, 3, 1, s[1], s[2], s[3]) if shut then rect(x, y + 2, 3, 1, INK[1], INK[2], INK[3]) elseif B.blue then rect(x, y, 3, 3, 104, 168, 236); px(x + 1, y + 1, INK[1], INK[2], INK[3]); px(x, y, 255, 255, 255) else rect(x, y, 3, 3, INK[1], INK[2], INK[3]); px(x, y, 255, 255, 255) end end end local CLOUDS = { { 5, 14, 0.9, 6 }, { 11, 10, -0.6, 40 } } function render() if not BG then bake() end gfx.blit_rgb(BG, 0, 0, W, H) local u = frame % CYC local t = frame / gfx.FPS for i = 1, #CLOUDS do local k = CLOUDS[i] local x = floor((k[4] + t * k[3]) % (W + k[2]) - k[2] + 0.5) blend_rect(x + 2, k[1], k[2] - 4, 1, 255, 255, 255, 0.7) blend_rect(x, k[1] + 1, k[2], 2, 255, 255, 255, 0.7) end local env = wag_env(u) local tx = tail(env, OMEGA * u, 3 * sin(frame * 0.045)) dust(u, tx) local tilt = pulse(u, 230, 330, 14) - pulse(u, 520, 590, 14) local tl = env > 0.3 and (1 + floor(1.5 * sin(frame * 0.5) + 1)) or 0 local shut = frame % 97 < 4 or (u >= 300 and u < 304) local fl = (u >= 190 and u < 206 and (u - 190) % 8 < 4) and 1 or 0 local fr = (u >= 470 and u < 490 and (u - 470) % 8 < 4) and 1 or 0 head(tilt, tl, shut, fl, fr) local lift = floor(3 * pulse(u, 400, 430, 15) + 0.5) local l, s = B.l, B.s rect(21, 54 - lift, 7, 4, l[1], l[2], l[3]) px(23, 56 - lift, s[1], s[2], s[3]); px(23, 57 - lift, s[1], s[2], s[3]) px(25, 56 - lift, s[1], s[2], s[3]); px(25, 57 - lift, s[1], s[2], s[3]) end