info = { type = "image", title = "Moon mochi bunny", category = "animals", author = "BRRRO", version = "1.0", license = "MIT", desc = "A round mochi bunny hops under the moon", api = 33, } local tr = ({ sk = { ["Hopping"] = "Skákanie", ["sits still"] = "sedí nehybne", ["gentle hops"] = "jemné poskoky", ["lively hops"] = "živé poskoky", ["Blush"] = "Červenanie", ["Fireflies"] = "Svetlušky" }, cs = { ["Hopping"] = "Skákání", ["sits still"] = "sedí nehybně", ["gentle hops"] = "jemné poskoky", ["lively hops"] = "živé poskoky", ["Blush"] = "Červenání", ["Fireflies"] = "Světlušky" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "hop", label = T("Hopping"), type = "int", default = 1, opts = { T("sits still"), T("gentle hops"), T("lively hops") } }, { key = "cheek", label = T("Blush"), type = "color", default = "#FF8FB1" }, { key = "fly", label = T("Fireflies"), type = "bool", default = true }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, sin, cos, sqrt, exp = math.floor, math.sin, math.cos, math.sqrt, math.exp local hash32, umod = math.hash32, math.umod local W, H = gfx.W, gfx.H local TAU = 6.28318 local OUTC = { 86, 56, 104 } local WHITE = { 255, 248, 250 } local SHADE = { 232, 216, 234 } local BELLY = { 252, 204, 216 } local EARIN = { 250, 170, 196 } local EYE = { 58, 38, 74 } local NOSE = { 238, 100, 134 } local PAL = { 0, 0, 0, OUTC[1], OUTC[2], OUTC[3], WHITE[1], WHITE[2], WHITE[3], SHADE[1], SHADE[2], SHADE[3], BELLY[1], BELLY[2], BELLY[3], EARIN[1], EARIN[2], EARIN[3] } local GY, CXB = 57, 28 local BW, BH = 26, 22 local function c3(c) return c[1], c[2], c[3] end local function pack(w, h, get) local rows = {} for y = 0, h - 1 do local row = {} for x = 0, w - 1 do row[x + 1] = get(x, y) end rows[y + 1] = string.char(table.unpack(row, 1, w)) end local cells = table.concat(rows) return { cells = cells, mask = (cells:gsub("[\1-\255]", "\255")), w = w, h = h } end local function shape(w, h, inside, paint) local ins = {} for y = 0, h - 1 do local o = y * w + 1 for x = 0, w - 1 do ins[o + x] = inside(x, y) end end return pack(w, h, function(x, y) local i = y * w + x + 1 if not ins[i] then return 0 end if x > 0 and x < w - 1 and y > 0 and y < h - 1 and ins[i - 1] and ins[i + 1] and ins[i - w] and ins[i + w] then return paint(x, y) end return 1 end) end local function body_in(x, y) local dy = (y + 0.5 - 11.5) / 11.5 local g = 0.86 + 0.14 * dy local dx = (x + 0.5 - 13) / (13 * g) return dx * dx + dy * dy <= 1 end local function body_paint(x, y) local bx, by = (x + 0.5 - 13) / 8, (y + 0.5 - 17.5) / 4.5 if bx * bx + by * by <= 1 then return 4 end if (x - 13) * -0.5 + (y - 11) * 0.45 > 5.2 then return 3 end return 2 end local EWID = { 2, 4, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 } local function ear_in(x, y) local hw = EWID[y + 1] / 2 return math.abs(x + 0.5 - 4) < hw end local function ear_paint(x, y) if y >= 3 and y <= 11 and math.abs(x + 0.5 - 4) < 1.1 then return 5 end return 2 end local BODY, EARB local function bake() BODY = shape(BW, BH, body_in, body_paint) local ear = shape(8, 14, ear_in, ear_paint) EARB = {} for i = 1, 7 do local r0 = 14 - 2 * i local c = ear.cells:sub(r0 * 8 + 1, (r0 + 2) * 8) EARB[i] = c end end bake() local function put(s, fx, fy, w, h) local ix, iy = floor(fx), floor(fy) local ax, ay = fx - ix, fy - iy if ax > 0.05 then gfx.blend_mask(s.mask, OUTC[1], OUTC[2], OUTC[3], ix + 1, iy, w, h, s.w, s.h, ax) end if ay > 0.05 then gfx.blend_mask(s.mask, OUTC[1], OUTC[2], OUTC[3], ix, iy + 1, w, h, s.w, s.h, ay) end gfx.blit_indexed(s.cells, PAL, ix, iy, w, h, s.w, s.h, true) end local BG = nil local MX, MY, MR = 47, 16, 10 local function disc(cx, cy, r, c) for y = floor(cy - r), floor(cy + r) do local dy = y + 0.5 - cy local k = r * r - dy * dy if k > 0 then local hw = sqrt(k) local x0 = floor(cx - hw + 0.5) rect(x0, y, floor(cx + hw + 0.5) - x0, 1, c3(c)) end end end local function build_bg() for y = 0, 47 do local t = y / 47 rect(0, y, W, 1, floor(76 + 86 * t + 0.5), floor(60 + 62 * t + 0.5), floor(136 + 42 * t + 0.5)) end for i = 1, 16 do local h = hash32(i * 0x9E3779B1) local x, y = umod(h, W), umod(h >> 8, 26) if not (x > MX - 17 and y < 30) then if i % 3 == 0 then px(x, y, 200, 180, 236) else px(x, y, 250, 240, 255) end end end disc(MX, MY, MR + 5, { 152, 112, 180 }) disc(MX, MY, MR + 2.5, { 188, 148, 196 }) disc(MX, MY, MR + 0.3, { 255, 242, 206 }) px(MX - 4, MY - 3, 238, 222, 180); px(MX - 3, MY - 3, 238, 222, 180) px(MX + 3, MY + 2, 238, 222, 180); px(MX + 2, MY + 5, 238, 222, 180) px(MX - 2, MY + 4, 238, 222, 180); px(MX + 5, MY - 3, 238, 222, 180) for x = 0, W - 1 do local top = floor(41 + 3 * sin(x * 0.09 + 1) + 2 * sin(x * 0.23) + 0.5) rect(x, top, 1, 50 - top, 98, 88, 152) end rect(0, 48, W, 1, 98, 164, 136) rect(0, 49, W, 9, 62, 124, 112) rect(0, 58, W, 6, 52, 106, 100) for i = 1, 26 do local h = hash32(i * 0x85EBCA6B) local x, y = umod(h, W), 50 + umod(h >> 8, 13) if x < 14 or x > 42 or y > 58 then px(x, y, 92, 152, 124); px(x, y - 1, 92, 152, 124) end end for k = 0, 2 do local x = 3 + k * 4 local top = 36 + k * 3 rect(x, top + 3, 1, 56 - top, 120, 150, 120) rect(x - 1, top, 3, 4, 232, 204, 176) px(x, top - 1, 250, 226, 196) end BG = gfx.snapshot(0, 0, W, H) end local HOPC = { [1] = 150, [2] = 96 } local CR, AIR, LAND = 9, 28, 16 local function pose(f, C) local b = sin(f * TAU / 84) * 0.02 if not C then return 0, 1 + b, 1 - b * 0.6 end f = f % C local T0 = C * 46 // 100 if f < T0 then return 0, 1 + b, 1 - b * 0.6 end f = f - T0 if f < CR then local q = 0.20 * sin(f / CR * 1.5708) return 0, 1 - q, 1 + q * 0.9 end f = f - CR if f < AIR then local u = f / AIR local s = sin(u * 3.14159) return 4 * u * (1 - u) * 13, 1 + 0.16 * s, 1 - 0.10 * s end f = f - AIR if f < LAND then local p = f / LAND local d = exp(-3 * p) * cos(p * 7) return 0, 1 - 0.22 * d, 1 + 0.18 * d end return 0, 1 + b, 1 - b * 0.6 end local CHR, CHG, CHB = 255, 143, 177 function on_settings() local c = cfg.cheek or { r = 255, g = 143, b = 177 } CHR, CHG, CHB = c.r, c.g, c.b end local function ear(bx, by, lean) local x, y = bx, by for i = 1, 7 do local a = lean * (i - 1) / 6 * 1.0 local nx, ny = x + sin(a) * 2, y - cos(a) * 2 gfx.blit_indexed(EARB[i], PAL, floor(nx + 0.5) - 4, floor(ny + 0.5), 8, 2, 8, 2, true) x, y = nx, ny end end local FX, FY, FA, FB, FP, FW = {}, {}, {}, {}, {}, {} for i = 1, 7 do local h = hash32(i * 0xC2B2AE35) FX[i], FY[i] = 6 + umod(h, 50), 28 + umod(h >> 8, 24) FA[i], FB[i] = 3 + umod(h >> 14, 4), 2 + umod(h >> 17, 3) FP[i] = umod(h >> 20, 628) / 100.0 FW[i] = 0.011 + umod(h >> 24, 8) * 0.0015 end local function glow(x, y, a) local ix, iy = floor(x), floor(y) local fx, fy = x - ix, y - iy blend_rect(ix, iy, 1, 1, 255, 244, 150, a * (1 - fx) * (1 - fy)) blend_rect(ix + 1, iy, 1, 1, 255, 244, 150, a * fx * (1 - fy)) blend_rect(ix, iy + 1, 1, 1, 255, 244, 150, a * (1 - fx) * fy) blend_rect(ix + 1, iy + 1, 1, 1, 255, 244, 150, a * fx * fy) end local function twitch(t, per, off) local u = (t + off) % per if u < 12 then local s = sin(u / 12 * 3.14159) return 0.55 * s * s end return 0 end local STEP_HZ = 30 function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local t = frame * STEP_HZ // gfx.FPS local C = HOPC[cfg.hop or 1] local lift, sy, sx = pose(t, C) local l1, l2 = pose(t - 3, C), pose(t - 6, C) local vyd = (l1 - l2) / 3 local wob = 0 if C then local la = t % C - (C * 46 // 100 + CR + AIR) if la >= 0 and la < 40 then wob = 0.5 * exp(-la * 0.11) * sin(la * 0.55) end end local ex = 0.30 * vyd + wob if ex < -0.10 then ex = -0.10 elseif ex > 0.42 then ex = 0.42 end local w, h = floor(BW * sx + 0.5), floor(BH * sy + 0.5) local fx = CXB - w / 2 local fy = GY - lift - h local cw = floor(24 * (1 - lift / 40) * (0.5 + sx * 0.5) + 0.5) blend_rect(CXB - cw // 2, GY - 1, cw, 2, 24, 64, 70, 0.55) blend_rect(CXB - cw // 2 + 2, GY + 1, cw - 4, 1, 24, 64, 70, 0.35) local sway = sin(t * 0.05) * 0.05 ear(fx + w * 0.30, fy + 5, -(0.14 + sway + ex + twitch(t, 137, 0))) ear(fx + w * 0.70, fy + 5, (0.14 - sway + ex + twitch(t, 211, 60))) put(BODY, fx, fy, w, h) local eyeY = floor(fy + h * 0.40 + 0.5) local lx = floor(fx + w * 0.27 + 0.5) local rx = floor(fx + w * 0.73 + 0.5) - 2 local ny = floor(fy + h * 0.52 + 0.5) local cx = floor(fx + w * 0.5 + 0.5) blend_rect(lx - 4, ny - 1, 4, 2, CHR, CHG, CHB, 0.85) blend_rect(rx + 4, ny - 1, 4, 2, CHR, CHG, CHB, 0.85) local shut = (t % 117) < 4 or sy < 0.88 or (C and lift == 0 and sx > 1.1) if shut then rect(lx, eyeY + 1, 3, 1, c3(EYE)); rect(rx, eyeY + 1, 3, 1, c3(EYE)) px(lx - 1, eyeY, c3(EYE)); px(lx + 3, eyeY, c3(EYE)) px(rx - 1, eyeY, c3(EYE)); px(rx + 3, eyeY, c3(EYE)) else rect(lx, eyeY, 2, 3, c3(EYE)); rect(rx, eyeY, 2, 3, c3(EYE)) px(lx, eyeY, 255, 255, 255); px(rx, eyeY, 255, 255, 255) end rect(cx - 1, ny, 2, 1, c3(NOSE)) px(cx - 2, ny + 1, c3(OUTC)); px(cx + 1, ny + 1, c3(OUTC)) rect(cx - 1, ny + 2, 2, 1, c3(OUTC)) if cfg.fly ~= false then for i = 1, 7 do local x = FX[i] + FA[i] * sin(t * FW[i] + FP[i]) local y = FY[i] + FB[i] * sin(t * FW[i] * 1.3 + FP[i] * 2) local a = sin(t * 0.045 + FP[i] * 3) if a > 0 then glow(x, y, a * 0.9) end end end end