info = { type = "image", title = "Plum blob", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "Goggle-eyed blob rolling eyes, tongue out", api = 33, } local tr = ({ sk = { ["Face"] = "Farba tváre", ["Plum"] = "Slivková", ["Mint"] = "Mätová", ["Tangerine"] = "Mandarínková", ["Rose"] = "Ružová" }, cs = { ["Face"] = "Barva tváře", ["Plum"] = "Švestková", ["Mint"] = "Mátová", ["Tangerine"] = "Mandarinková", ["Rose"] = "Růžová" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "face", label = T("Face"), type = "int", default = "plum", opts = { keys = { "plum", "mint", "tangerine", "rose" }, T("Plum"), T("Mint"), T("Tangerine"), T("Rose") } }, } local rect, px, blend, blit_idx = gfx.rect, gfx.px, gfx.blend, gfx.blit_indexed local blit_rgb, snapshot = gfx.blit_rgb, gfx.snapshot local floor, sqrt, min, max = math.floor, math.sqrt, math.min, math.max local W, H = gfx.W, gfx.H local FACES = { plum = { face = { 156, 98, 204 }, bg = { 244, 190, 70 }, dots = { 252, 216, 112 } }, mint = { face = { 92, 204, 160 }, bg = { 236, 120, 110 }, dots = { 248, 152, 136 } }, tangerine = { face = { 248, 150, 50 }, bg = { 70, 100, 200 }, dots = { 98, 132, 228 } }, rose = { face = { 240, 120, 162 }, bg = { 60, 170, 170 }, dots = { 92, 198, 192 } }, } local F = FACES.plum local FCOL, SHADE, OUTL, LIGHT = {}, {}, {}, {} local FX, FY, R = 32, 36, 22 local EL, ER, EY, ER_ = 23, 41, 29, 7 local function scale(c, k) return { floor(c[1] * k + 0.5), floor(c[2] * k + 0.5), floor(c[3] * k + 0.5) } end local function toward(c, k) return { floor(c[1] + (255 - c[1]) * k + 0.5), floor(c[2] + (255 - c[2]) * k + 0.5), floor(c[3] + (255 - c[3]) * k + 0.5) } end local function circ(cx, cy, r, c) for dy = -r, r do local hw = floor(sqrt((r + 0.5) ^ 2 - dy * dy)) rect(cx - hw, cy + dy, 2 * hw + 1, 1, c[1], c[2], c[3]) end end local function st_face() rect(0, 0, W, H, F.bg[1], F.bg[2], F.bg[3]) for gy = 0, 10 do for gx = 0, 10 do rect(gx * 6 + (gy % 2) * 3, gy * 6, 2, 2, F.dots[1], F.dots[2], F.dots[3]) end end circ(FX, FY, R + 1, OUTL) circ(FX, FY, R, SHADE) circ(FX - 1, FY - 1, R - 1, FCOL) circ(17, 20, 2, LIGHT) circ(13, 25, 1, LIGHT) end local function st_features() local d = OUTL for _, sp in ipairs({ { 32, 3, 3 }, { 26, 7, 2 }, { 38, 7, 2 } }) do for y = sp[2], 13 do local hw = floor((y - sp[2]) / (13 - sp[2]) * sp[3] + 0.5) rect(sp[1] - hw, y, 2 * hw + 1, 1, SHADE[1], SHADE[2], SHADE[3]) end end for _, cx in ipairs({ EL, ER }) do circ(cx, EY, ER_ + 1, d) circ(cx, EY, ER_, { 255, 255, 255 }) end for _, cx in ipairs({ 14, 50 }) do for dy = -3, 3 do local hw = floor(4 * sqrt(1 - (dy / 3.6) ^ 2) + 0.5) gfx.blend_rect(cx - hw, 44 + dy, 2 * hw + 1, 1, 255, 110, 140, 0.34) end end for x = 24, 40 do local y = 45 + floor((1 - ((x - 32) / 9) ^ 2) * 3.5 + 0.5) px(x, y, 40, 14, 40) px(x, y + 1, 40, 14, 40) end end local STAGES = { st_face, st_features } local STAGE, PART, BG = 1, nil, nil local function build() if STAGE > 1 then blit_rgb(PART, 0, 0, W, H) end STAGES[STAGE]() PART = snapshot(0, 0, W, H) STAGE = STAGE + 1 if STAGE > #STAGES then BG = PART end end function on_settings() F = FACES[cfg.face] or FACES.plum FCOL, SHADE, OUTL, LIGHT = F.face, scale(F.face, 0.66), scale(F.face, 0.34), toward(F.face, 0.28) BG, STAGE = nil, 1 end local PUPIL_PAL = { 0, 0, 0, 26, 18, 42, 255, 255, 255 } local PUPIL = ("..kkk..\n.khkkk.\nkkkkkkk\nkkkkkkk\nkkkkkkk\n.kkkkk.\n..kkk.."):gsub("\n", "") local PMAP = { ["."] = "\0", k = "\1", h = "\2" } PUPIL = PUPIL:gsub(".", PMAP) local MOUTH_PAL = { 0, 0, 0, 44, 14, 44, 236, 74, 108, 178, 40, 84 } local TMAP = { ["."] = "\0", d = "\1", r = "\2", g = "\3" } local function pose(rows) return (table.concat(rows):gsub(".", TMAP)) end local function tongue(tail) local r = { ".ddddddddd.", ".ddddddddd." } for i = 1, #tail do r[#r + 1] = tail[i] end while #r < 9 do r[#r + 1] = "..........." end return pose(r) end local TONGUES = { tongue({ "..ddrrrdd..", "...drrrd...", "....rrr...." }), tongue({ "..ddrrrdd..", "...drrrd...", "...rrrrr...", "...rrgrr...", "...rrgrr...", "....rgr....", ".....r....." }), tongue({ "..ddrrrdd..", "...drrrd...", "...rrrrr...", "..rrgrr....", "..rrgrr....", "...rgr.....", "..r........" }), tongue({ "..ddrrrdd..", "...drrrd...", "...rrrrr...", "....rrgrr..", "....rrgrr..", ".....rgr...", "......r...." }), } local CYCLE = 270 local GAZE = { { 0, 0, 0 }, { 40, 0, 0 }, { 55, 3, 0 }, { 70, 2, 2 }, { 85, 0, 3 }, { 100, -3, 1 }, { 115, -3, -2 }, { 130, 0, -3 }, { 145, 0, 0 }, { 160, 0, 3 }, { 215, 0, 3 }, { 235, 3, -1 }, { 255, 0, 0 }, { 270, 0, 0 }, } local TONGUE_AT = { { 150, 1 }, { 156, 2 }, { 164, 3 }, { 170, 2 }, { 176, 4 }, { 182, 2 }, { 188, 3 }, { 194, 2 }, { 200, 4 }, { 206, 2 }, { 214, 1 }, { 220, 0 }, } local LIDS = { 6, 12, 17, 17, 12, 6 } local BLINKS = { 100, 245 } local function gaze(c) for i = 1, #GAZE - 1 do local a, b = GAZE[i], GAZE[i + 1] if c < b[1] then local t = (c - a[1]) / (b[1] - a[1]) t = t * t * (3 - 2 * t) local x, y = a[2] + (b[2] - a[2]) * t, a[3] + (b[3] - a[3]) * t local l = sqrt(x * x + y * y) if l > 3.4 then x, y = x * 3.4 / l, y * 3.4 / l end return floor(x + 0.5), floor(y + 0.5) end end return 0, 0 end local function lid(cx, n) for dy = -ER_ - 1, -ER_ - 1 + n - 1 do local hw = floor(sqrt((ER_ + 1.5) ^ 2 - dy * dy)) rect(cx - hw, EY + dy, 2 * hw + 1, 1, FCOL[1], FCOL[2], FCOL[3]) end if n >= 17 then rect(cx - 6, EY + 2, 13, 1, OUTL[1], OUTL[2], OUTL[3]) rect(cx - 7, EY + 1, 1, 1, OUTL[1], OUTL[2], OUTL[3]) rect(cx + 7, EY + 1, 1, 1, OUTL[1], OUTL[2], OUTL[3]) else local dy = -ER_ - 1 + n - 1 local hw = floor(sqrt((ER_ + 1.5) ^ 2 - dy * dy)) rect(cx - hw, EY + dy, 2 * hw + 1, 1, OUTL[1], OUTL[2], OUTL[3]) end end function render() if not BG then build() return end blit_rgb(BG, 0, 0, W, H) local c = frame % CYCLE local dx, dy = gaze(c) blit_idx(PUPIL, PUPIL_PAL, EL - 3 + dx, EY - 3 + dy, 7, 7, 7, 7, true) blit_idx(PUPIL, PUPIL_PAL, ER - 3 + dx, EY - 3 + dy, 7, 7, 7, 7, true) for i = 1, #BLINKS do local n = LIDS[c - BLINKS[i] + 1] if n then lid(EL, n); lid(ER, n) end end local tp = 0 for i = 1, #TONGUE_AT do if c >= TONGUE_AT[i][1] then tp = TONGUE_AT[i][2] end end if tp > 0 then blit_idx(TONGUES[tp], MOUTH_PAL, 27, 46, 11, 9, 11, 9, true) end end