info = { type = "image", title = "Dandelion sneeze", category = "animals", author = "BRRRO", version = "1.0", license = "MIT", desc = "A sprout grows on a cat, then a sneeze", api = 33, } local tr = ({ sk = { ["Coat"] = "Srsť", ["Calico"] = "Škvrnitá", ["Ginger"] = "Ryšavá", ["Grey"] = "Sivá", ["Seeds"] = "Semienka" }, cs = { ["Coat"] = "Srst", ["Calico"] = "Strakatá", ["Ginger"] = "Zrzavá", ["Grey"] = "Šedá", ["Seeds"] = "Semínka" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "coat", label = T("Coat"), type = "int", default = "calico", opts = { keys = { "calico", "ginger", "grey" }, T("Calico"), T("Ginger"), T("Grey") } }, { key = "seeds", label = T("Seeds"), type = "int", min = 6, max = 24, default = 14 }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local blit, blit_rgb, snapshot = gfx.blit_indexed, gfx.blit_rgb, gfx.snapshot local floor, ceil, sin, cos, sqrt, min, max, abs = math.floor, math.ceil, math.sin, math.cos, math.sqrt, math.min, math.max, math.abs local hash32, umod = math.hash32, math.umod local char, unpack, concat = string.char, table.unpack, table.concat local W, H = gfx.W, gfx.H local TAU = 6.28318 local CYCLE = 560 local COATS = { calico = { { 250, 162, 64 }, { 255, 202, 122 }, { 214, 120, 40 }, { 255, 248, 238 }, { 232, 214, 196 }, { 112, 66, 44 } }, ginger = { { 250, 162, 64 }, { 255, 202, 122 }, { 214, 120, 40 }, { 255, 248, 238 }, { 232, 214, 196 }, { 214, 120, 40 } }, grey = { { 160, 168, 184 }, { 200, 206, 218 }, { 110, 116, 140 }, { 255, 250, 250 }, { 214, 218, 228 }, { 84, 88, 108 } }, } local PAL = {} local CPAL = { 0, 0, 0, 92, 170, 214, 150, 214, 240, 50, 110, 170, 214, 240, 252, 30, 70, 120 } function on_settings() local c = COATS[cfg.coat] or COATS.calico local o = cfg.coat == "grey" and { 60, 62, 84 } or { 92, 50, 40 } PAL = { 0, 0, 0 } for i = 1, 6 do PAL[#PAL + 1], PAL[#PAL + 2], PAL[#PAL + 3] = c[i][1], c[i][2], c[i][3] end for _, v in ipairs({ o[1], o[2], o[3], 255, 150, 160, 248, 168, 162 }) do PAL[#PAL + 1] = v end end local function newgrid(w, h) local g = {} for i = 1, w * h do g[i] = 0 end return g end local function fell(g, w, h, cx, cy, rx, ry, c, only) for y = max(0, floor(cy - ry)), min(h - 1, ceil(cy + ry)) do for x = max(0, floor(cx - rx)), min(w - 1, ceil(cx + rx)) do local dx, dy = (x + 0.5 - cx) / rx, (y + 0.5 - cy) / ry if dx * dx + dy * dy <= 1 then local i = y * w + x + 1 if not only or g[i] == only then g[i] = c end end end end end local function ftri(g, w, h, x1, y1, x2, y2, x3, y3, c) for y = max(0, floor(min(y1, y2, y3))), min(h - 1, ceil(max(y1, y2, y3))) do for x = max(0, floor(min(x1, x2, x3))), min(w - 1, ceil(max(x1, x2, x3))) do local qx, qy = x + 0.5, y + 0.5 local d1 = (qx - x2) * (y1 - y2) - (x1 - x2) * (qy - y2) local d2 = (qx - x3) * (y2 - y3) - (x2 - x3) * (qy - y3) local d3 = (qx - x1) * (y3 - y1) - (x3 - x1) * (qy - y1) if not ((d1 < 0 or d2 < 0 or d3 < 0) and (d1 > 0 or d2 > 0 or d3 > 0)) then g[y * w + x + 1] = c end end end end local function outline(g, w, h, to, last) local o = {} for y = 0, h - 1 do for x = 0, w - 1 do local i = y * w + x + 1 local c = g[i] if c ~= 0 and c <= last and (x == 0 or y == 0 or x == w - 1 or y == h - 1 or g[i - 1] == 0 or g[i + 1] == 0 or g[i - w] == 0 or g[i + w] == 0) then o[i] = to end end end for i, c in pairs(o) do g[i] = c end end local function pack(g, w, h) local t = {} for y = 0, h - 1 do t[y + 1] = char(unpack(g, y * w + 1, y * w + w)) end return concat(t) end local BODY, TAIL, HEAD, CAN = nil, {}, {}, {} local BWID, BHEI, HWID, HHEI, TWID, THEI = 26, 14, 22, 18, 8, 14 local function body_sprite() local g = newgrid(BWID, BHEI) fell(g, BWID, BHEI, 13, 8.2, 12.6, 6, 1) fell(g, BWID, BHEI, 12, 6, 9, 3.2, 2, 1) fell(g, BWID, BHEI, 4.5, 7, 4, 4.5, 6, 1) fell(g, BWID, BHEI, 13, 11.5, 6.5, 3.2, 4) fell(g, BWID, BHEI, 8, 12.4, 3, 1.7, 4) fell(g, BWID, BHEI, 18, 12.4, 3, 1.7, 4) outline(g, BWID, BHEI, 7, 6) BODY = pack(g, BWID, BHEI) end local function head_sprite(flat) local g = newgrid(HWID, HHEI) if flat then ftri(g, HWID, HHEI, 0, 7, 0.5, 2.5, 7, 4.5, 1) ftri(g, HWID, HHEI, 22, 7, 21.5, 2.5, 15, 4.5, 1) else ftri(g, HWID, HHEI, 1, 6.5, 2, 0.2, 8, 3.2, 1) ftri(g, HWID, HHEI, 21, 6.5, 20, 0.2, 14, 3.2, 1) end fell(g, HWID, HHEI, 11, 10.5, 10.5, 7.2, 1) fell(g, HWID, HHEI, 10, 7.5, 7, 3.5, 2, 1) fell(g, HWID, HHEI, 5, 6, 4, 3.6, 6, 1) fell(g, HWID, HHEI, 11, 13.8, 5.5, 3.2, 4) outline(g, HWID, HHEI, 7, 6) if flat then ftri(g, HWID, HHEI, 1.4, 6.2, 1.6, 3.6, 5.6, 5, 8) ftri(g, HWID, HHEI, 20.6, 6.2, 20.4, 3.6, 16.4, 5, 8) else ftri(g, HWID, HHEI, 2.8, 5, 3.2, 2.2, 6.2, 3.8, 8) ftri(g, HWID, HHEI, 19.2, 5, 18.8, 2.2, 15.8, 3.8, 8) end for _, p in ipairs({ { 10, 3 }, { 11, 3 }, { 10, 4 }, { 11, 4 }, { 7, 4 }, { 14, 4 } }) do g[p[2] * HWID + p[1] + 1] = 3 end g[12 * HWID + 11] = 8; g[12 * HWID + 12] = 8 g[14 * HWID + 10] = 7; g[15 * HWID + 11] = 7; g[15 * HWID + 12] = 7; g[14 * HWID + 13] = 7 fell(g, HWID, HHEI, 4.5, 12, 2, 1.2, 9); fell(g, HWID, HHEI, 17.5, 12, 2, 1.2, 9) return pack(g, HWID, HHEI) end local function tail_sprite(k) local g = newgrid(TWID, THEI) for i = 0, 22 do local t = i / 22 fell(g, TWID, THEI, 3 + 2.2 * sin(t * 2.6 + (k - 1) * 1.2) * (0.4 + t), 1.4 + 11 * t, 1.8, 1.8, t > 0.82 and 3 or 1) end outline(g, TWID, THEI, 7, 6) return pack(g, TWID, THEI) end local CW, CH = 34, 28 local function can_sprite(k) local a = -k * 25 * 0.01745 local c, s = cos(a), sin(a) local g = newgrid(CW, CH) local function put(x, y, idx) local X, Y = floor(21 + x * c - y * s), floor(11 + x * s + y * c) if X >= 0 and X < CW and Y >= 0 and Y < CH then g[Y * CW + X + 1] = idx end end for xi = -10, 10 do for yi = -8, 8 do local x, y = xi * 0.5, yi * 0.5 put(x, y, y < -3.4 and 4 or (y < -2.2 and 2 or ((x > 3 or y > 2.6) and 3 or 1))) end end for i = 0, 20 do local t = i / 20 for _, d in ipairs({ { 0, 0 }, { 0.5, 0 }, { 0, 0.5 }, { 0.5, 0.5 } }) do put(-5 - 6 * t + d[1], 2.5 - 5.5 * t + d[2], 1) end end for xi = -5, 5 do for yi = -5, 5 do if xi * xi + yi * yi <= 20 then put(-12.5 + xi * 0.5, -4.5 + yi * 0.5, xi * xi + yi * yi > 12 and 3 or 2) end end end for i = -8, 8 do local th = i * 0.17 put(5 + 3.5 * cos(th), 4 * sin(th), 3); put(5.5 + 3.5 * cos(th), 4 * sin(th), 3) end outline(g, CW, CH, 5, 4) return pack(g, CW, CH) end local function cached(tab, k, f) local s = tab[k] if not s then s = f(k); tab[k] = s end return s end local function can_tip(k) local a = -k * 25 * 0.01745 return -12.5 * cos(a) + 4.5 * sin(a), -12.5 * sin(a) - 4.5 * cos(a) end local BG = nil local function hills(base, amp, ph, c) for x = 9, 54 do local y = floor(base - amp * (0.6 + 0.4 * sin(x * 0.13 + ph)) - 2 * sin(x * 0.31 + ph * 2) + 0.5) rect(x, y, 1, 45 - y, c[1], c[2], c[3]) end end local function bake_bg() rect(0, 0, W, H, 252, 228, 216) for x = 0, W - 1, 8 do rect(x, 52, 4, 12, 247, 216, 208) end for y = 3, 44 do local t = (y - 3) / 41 rect(9, y, 46, 1, floor(128 + 88 * t), floor(198 + 40 * t), floor(246 + 6 * t)) end hills(33, 5, 0.5, { 178, 220, 180 }) hills(39, 4, 2.0, { 128, 196, 132 }) rect(13, 36, 5, 4, 255, 248, 240); rect(12, 35, 7, 1, 226, 90, 90); rect(13, 34, 5, 1, 226, 90, 90); rect(14, 33, 3, 1, 226, 90, 90) rect(15, 38, 1, 2, 150, 100, 70) rect(46, 37, 3, 3, 70, 150, 80); rect(47, 35, 1, 2, 70, 150, 80); rect(51, 38, 2, 2, 70, 150, 80) rect(9, 3, 1, 42, 180, 128, 90); rect(54, 3, 1, 42, 180, 128, 90) local cols = { { 246, 148, 170 }, { 232, 120, 150 }, { 252, 178, 196 } } for x = 0, 8 do local c = cols[x % 3 + 1] rect(x, 0, 1, 46, c[1], c[2], c[3]) local d = cols[(8 - x) % 3 + 1] rect(55 + x, 0, 1, 46, d[1], d[2], d[3]) end rect(0, 0, W, 3, 252, 178, 196); rect(0, 3, W, 1, 214, 100, 130) rect(0, 29, 9, 2, 255, 226, 120); rect(55, 29, 9, 2, 255, 226, 120) rect(3, 46, 58, 2, 246, 210, 166) rect(3, 48, 58, 3, 220, 168, 118) rect(3, 51, 58, 1, 166, 116, 80) blend_rect(0, 52, W, 2, 120, 60, 60, 0.12) blend_rect(19, 46, 26, 1, 120, 70, 50, 0.3) BG = snapshot(0, 0, W, H) end local function fblob(cx, cy, rx, ry, c, a) for y = floor(cy - ry), ceil(cy + ry) - 1 do local v = (y + 0.5 - cy) / ry if v > -1 and v < 1 then local hw = rx * sqrt(1 - v * v) local x0 = floor(cx - hw + 0.5) local w = floor(cx + hw + 0.5) - x0 if w > 0 then if a and a < 1 then blend_rect(x0, y, w, 1, c[1], c[2], c[3], a) else rect(x0, y, w, 1, c[1], c[2], c[3]) end end end end end local function frect(x, y, w, r, g, b, a) local x0 = floor(x) local f = x - x0 blend_rect(x0 + 1, y, w - 1, 1, r, g, b, a) blend(x0, y, r, g, b, a * (1 - f)) blend(x0 + w, y, r, g, b, a * f) end local function splat(x, y, r, g, b, a) local x0, y0 = floor(x), floor(y) local fx, fy = x - x0, y - y0 blend(x0, y0, r, g, b, a * (1 - fx) * (1 - fy)) blend(x0 + 1, y0, r, g, b, a * fx * (1 - fy)) blend(x0, y0 + 1, r, g, b, a * (1 - fx) * fy) blend(x0 + 1, y0 + 1, r, g, b, a * fx * fy) end local function ease(u) u = u < 0 and 0 or (u > 1 and 1 or u); return u * u * (3 - 2 * u) end local GREEN, GREEN_D, LEAF, LEAF_D = { 84, 178, 70 }, { 56, 140, 56 }, { 118, 206, 94 }, { 70, 156, 70 } local YEL, YEL_C, WHITE, CREAM = { 255, 214, 60 }, { 255, 150, 40 }, { 252, 252, 255 }, { 226, 222, 200 } local function plant(t, base) local h, ls = 3, 0.4 if t >= 100 and t < 210 then h = 3 + 6 * ease((t - 100) / 110); ls = 0.4 + 0.6 * ease((t - 100) / 100) elseif t >= 210 and t < 380 then h, ls = 9, 1 elseif t >= 380 and t < 440 then local k = ease((t - 380) / 60); h = 9 - 6 * k; ls = 1 - 0.6 * k end local top = base - h rect(31, floor(top + 0.5), 2, floor(h + 0.5) + 1, GREEN[1], GREEN[2], GREEN[3]) rect(31, floor(top + 0.5), 1, floor(h + 0.5) + 1, LEAF[1], LEAF[2], LEAF[3]) local rx, ry = 1.5 + 2.5 * ls, 0.8 + 1.1 * ls fblob(31 - rx * 0.8, base - h * 0.35, rx, ry, LEAF_D) fblob(31 - rx * 0.8, base - h * 0.35 - 0.4, rx * 0.85, ry * 0.7, LEAF) fblob(33 + rx * 0.8, base - h * 0.62, rx, ry, LEAF_D) fblob(33 + rx * 0.8, base - h * 0.62 - 0.4, rx * 0.85, ry * 0.7, LEAF) local cx = 32 if t >= 205 and t < 262 then local k = ease((t - 205) / 23) fblob(cx, top - 1.4, 2 * k + 0.4, 2.6 * k + 0.4, GREEN_D) fblob(cx, top - 1.8, 1.5 * k + 0.3, 2 * k + 0.3, LEAF) end if t >= 228 and t < 340 then local ky = ease((t - 228) / 34) local fade = ease((t - 262) / 38) local trem = (t >= 318 and t < 340) and 0.8 * sin(t * 2.2) or 0 if fade < 1 and t < 300 then local r = 1 + 3.2 * ky fblob(cx, top - r * 0.9, r, r, YEL, 1 - fade) fblob(cx, top - r * 0.9, r * 0.45, r * 0.45, YEL_C, 1 - fade) end if fade > 0 then local r = 2 + 3.5 * fade local pc = top - 3.6 - r * 0.4 fblob(cx + trem, pc, r, r, WHITE, fade < 1 and fade or nil) if fade > 0.5 then local a = (fade - 0.5) * 2 for k = 0, 9 do local an = k * 0.628 blend(floor(cx + trem + cos(an) * (r + 1)), floor(pc + sin(an) * (r + 1)), 240, 244, 255, 0.8 * a) end fblob(cx + trem, pc, 1.6, 1.6, CREAM, a) end end elseif t >= 340 and t < 395 then fblob(cx, top - 0.5, 1.2, 1, CREAM, 1 - (t - 340) / 55) end end local SEEDS = {} for i = 1, 24 do local h = hash32(i * 0x9E3779B1) SEEDS[i] = { vx = 0.6 + umod(h, 100) / 100, vy = -0.5 + umod(h >> 8, 120) / 100, vd = 0.15 + umod(h >> 14, 15) / 100, vr = umod(h >> 18, 5) / 100 - 0.01, tau = 18 + umod(h >> 22, 12), amp = 1 + umod(h >> 25, 15) / 10, ph = umod(h >> 8, 628) / 100, delay = umod(h >> 3, 28) } end local function draw_seeds(age0, n, sx, sy) for i = 1, n do local s = SEEDS[i] local a = age0 - s.delay if a > 0 and a < 260 then local q = a / (a + s.tau) local x = sx + s.vd * a + (s.vx - s.vd) * s.tau * q local y = sy + s.vr * a + (s.vy - s.vr) * s.tau * q + s.amp * sin(0.06 * a + s.ph) if x < W + 3 then splat(x, y, 255, 255, 255, 0.95) blend(floor(x) - 1, floor(y), 255, 255, 255, 0.5) blend(floor(x) + 2, floor(y), 255, 255, 255, 0.5) blend(floor(x + 0.5), floor(y) - 1, 255, 255, 255, 0.7) blend(floor(x + 0.5), floor(y) + 2, 150, 128, 100, 0.85) end end end end local EYE = { 48, 28, 36 } local function eyes(hx, hy, style) for _, ex in ipairs({ hx + 6, hx + 14 }) do local ey = hy + 8 if style == "open" then rect(ex, ey, 2, 3, EYE[1], EYE[2], EYE[3]) px(ex, ey, 255, 255, 255) elseif style == "blink" then rect(ex, ey + 1, 2, 1, EYE[1], EYE[2], EYE[3]) elseif style == "happy" then px(ex - 1, ey + 2, EYE[1], EYE[2], EYE[3]); px(ex, ey + 1, EYE[1], EYE[2], EYE[3]) px(ex + 1, ey + 1, EYE[1], EYE[2], EYE[3]); px(ex + 2, ey + 2, EYE[1], EYE[2], EYE[3]) else if ex < hx + 10 then px(ex - 1, ey, EYE[1], EYE[2], EYE[3]); px(ex, ey + 1, EYE[1], EYE[2], EYE[3]); px(ex - 1, ey + 2, EYE[1], EYE[2], EYE[3]) else px(ex + 2, ey, EYE[1], EYE[2], EYE[3]); px(ex + 1, ey + 1, EYE[1], EYE[2], EYE[3]); px(ex + 2, ey + 2, EYE[1], EYE[2], EYE[3]) end end end end function render() if not BG then bake_bg() return end if not BODY then body_sprite(); cached(TAIL, 1, tail_sprite); blit_rgb(BG, 0, 0, W, H) return end if not HEAD[1] then HEAD[1] = head_sprite(false); blit_rgb(BG, 0, 0, W, H) return end local t = frame % CYCLE blit_rgb(BG, 0, 0, W, H) gfx.clip(10, 4, 44, 41) frect((6 + frame * 0.04) % 60 - 14, 12, 14, 255, 252, 255, 0.85) frect((6 + frame * 0.04) % 60 - 14 + 2, 13, 10, 255, 252, 255, 0.85) frect((40 - frame * 0.025) % 60 - 10, 22, 10, 255, 252, 255, 0.8) gfx.clip() local tk = ({ 1, 2, 3, 2 })[t // 12 % 4 + 1] local ts = cached(TAIL, tk, tail_sprite) blit(ts, PAL, 40, 37, TWID, THEI, TWID, THEI, true) blit(BODY, PAL, 19, 32, BWID, BHEI, BWID, BHEI, true) local dy = 0 if t >= 320 and t < 338 then dy = -1 elseif t >= 338 and t < 340 then dy = -2 elseif t >= 340 and t < 350 then dy = 2 elseif t >= 350 and t < 358 then dy = 1 end local flat = (t >= 92 and t < 150) or (t >= 340 and t < 352) local hy = 21 + dy plant(t, hy + 4) local hs = flat and (HEAD[2] or head_sprite(true)) or (HEAD[1] or head_sprite(false)) if flat then HEAD[2] = hs else HEAD[1] = hs end blit(hs, PAL, 21, hy, HWID, HHEI, HWID, HHEI, true) local style = "open" if (t >= 92 and t < 170) then style = "happy" elseif t >= 300 and t < 352 then style = "squint" elseif t % 150 >= 40 and t % 150 < 44 then style = "blink" end eyes(21, hy, style) if t >= 340 and t < 352 then rect(31, hy + 13, 2, 2, 100, 36, 48) px(31, hy + 14, 255, 140, 150); px(32, hy + 14, 255, 140, 150) local k = (t - 340) / 12 for j = 0, 7 do local an = j * 0.785 + 0.39 local r0 = 11 + 6 * k for q = 0, 1 do blend(floor(31.5 + cos(an) * (r0 + q)), floor(hy + 10 + sin(an) * (r0 + q)), 255, 255, 255, 0.85 * (1 - k)) end end end if t >= 60 and t < 195 then local k, cx = 0, 78 if t < 85 then cx = 78 - 34 * ease((t - 60) / 25) elseif t < 92 then cx, k = 44, 1 elseif t < 150 then cx, k = 44, 2 elseif t < 158 then cx, k = 44, 1 elseif t < 165 then cx = 44 else cx = 44 + 34 * ease((t - 165) / 30) end local cs = cached(CAN, k + 1, function(i) return can_sprite(i - 1) end) blit(cs, CPAL, floor(cx) - 21, 9 - 11, CW, CH, CW, CH, true) if t >= 92 and t < 150 then local tx, ty = can_tip(2) tx, ty = 44 + tx, 9 + ty for j = 0, 5 do local a = (t + j * 3) % 18 local y = ty + 0.5 * 0.1 * a * a if y < hy + 1.5 then rect(floor(tx + 0.5), floor(y), 1, 2, 160, 214, 255) end end for j = 0, 2 do blend(floor(31 + (t + j * 5) % 3 * 1.5 + j), hy, 190, 226, 255, 0.7) end end end if t >= 340 then draw_seeds(t - 340, cfg.seeds or 14, 32, 10) end end