info = { type = "image", title = "Cape cliff", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "Cloaked figure on a cliff under a crescent moon", api = 33, } local tr = ({ sk = { ["Cloak"] = "Plášť", ["Wind"] = "Vietor", ["Calm"] = "Pokojný", ["Breeze"] = "Vánok", ["Gale"] = "Víchrica", ["Shooting stars"] = "Padajúce hviezdy" }, cs = { ["Cloak"] = "Plášť", ["Wind"] = "Vítr", ["Calm"] = "Klidný", ["Breeze"] = "Vánek", ["Gale"] = "Vichřice", ["Shooting stars"] = "Padající hvězdy" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "cloak", label = T("Cloak"), type = "color", default = "#D2262C" }, { key = "wind", label = T("Wind"), type = "int", default = "breeze", opts = { keys = { "calm", "breeze", "gale" }, T("Calm"), T("Breeze"), T("Gale") } }, { key = "shoot", label = T("Shooting stars"), type = "bool", default = true }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local floor, sin, sqrt, min, max = math.floor, math.sin, math.sqrt, math.min, math.max local hash32, umod = math.hash32, math.umod local W, H = gfx.W, gfx.H local X0, GROUND = 20, 50 local FX = 27 local function lerp3(a, b, t) return floor(a[1] + (b[1] - a[1]) * t + 0.5), floor(a[2] + (b[2] - a[2]) * t + 0.5), floor(a[3] + (b[3] - a[3]) * t + 0.5) end local function span(y, a, b, r, g, bl, al) local fa, fb = floor(a), floor(b) if fa == fb then if b > a then blend(fa, y, r, g, bl, (b - a) * al) end return end if a > fa then blend(fa, y, r, g, bl, (1 - a + fa) * al); fa = fa + 1 end if fb > fa then blend_rect(fa, y, fb - fa, 1, r, g, bl, al) end if b > fb then blend(fb, y, r, g, bl, (b - fb) * al) end end local function dot(x, y, r, g, b, a) local ix, iy = floor(x), floor(y) local fx, fy = x - ix, y - iy blend(ix, iy, r, g, b, a * (1 - fx) * (1 - fy)) blend(ix + 1, iy, r, g, b, a * fx * (1 - fy)) blend(ix, iy + 1, r, g, b, a * (1 - fx) * fy) blend(ix + 1, iy + 1, r, g, b, a * fx * fy) end local MX, MY = 51, 12 local RB = { 30, 30, 29, 29, 30, 29, 28, 28, 29, 28, 27, 27, 28, 27 } local STARS = {} for i = 1, 30 do local k = hash32(i * 0x9E3779B1) local x, y = umod(k, W), umod(k >> 8, 44) local dx, dy = x - MX, y - MY if dx * dx + dy * dy > 120 and not (y > 30 and x < 36) then STARS[#STARS + 1] = { x, y, umod(k >> 16, 628) / 100, i % 3 == 0 } end end local LIGHTS = { { 44, 60 }, { 47, 61 }, { 53, 60 }, { 58, 61 } } local BG local function build_bg() for y = 0, H - 1 do rect(0, y, W, 1, lerp3({ 8, 10, 30 }, { 40, 52, 118 }, max(0, min(1, (y - 22) / 35)))) end for _, d in ipairs({ { 14, 0.05 }, { 11, 0.08 }, { 8.5, 0.1 } }) do for j = -14, 14 do if d[1] * d[1] - j * j > 0 then local hw = sqrt(d[1] * d[1] - j * j) blend_rect(floor(MX - hw + 0.5), MY + j, floor(2 * hw + 0.5), 1, 150, 180, 255, d[2]) end end end for y = MY - 8, MY + 8 do for x = MX - 8, MX + 8 do local a = (x - MX) ^ 2 + (y - MY) ^ 2 local b = (x - MX - 3) ^ 2 + (y - MY + 1.8) ^ 2 if a <= 6.5 * 6.5 and b > 5.7 * 5.7 then px(x, y, 252, 244, 206) end end end for x = 30, W - 1 do local top = 59 + floor(1.2 * sin(x * 0.4) + 0.5) rect(x, top, 1, H - top, 12, 16, 40) end for y = GROUND, H - 1 do local rb = RB[y - GROUND + 1] rect(0, y, rb, 1, 84, 58, 46) for x = (y % 2), rb - 1, 2 do if (x + y) % 4 < 2 and y > GROUND + 2 then px(x, y, 70, 46, 40) end end rect(rb - 2, y, 2, 1, 112, 82, 64) px(rb - 1, y, 126, 96, 74) end rect(0, GROUND, 30, 2, 36, 74, 66) rect(0, GROUND, 30, 1, 66, 116, 98) rect(0, H - 4, 30, 4, 52, 36, 38) for i = 1, 10 do local k = hash32(i * 0x85EBCA6B) px(umod(k, 26), GROUND + 3 + umod(k >> 8, 9), 54, 36, 34) end BG = gfx.snapshot(0, 0, W, H) end local CAPE = { 210, 38, 44 } local SHADE, RIM = { 116, 20, 30 }, { 232, 128, 150 } local SKIN, BOOT, SCARF = { 214, 160, 128 }, { 60, 34, 40 }, { 238, 208, 206 } local EXT = { 0, 1.2, 2.5, 4, 5.5 } local RR = { 3, 3, 3, 3, 4, 4, 4, 5, 5, 5 } local LB = { -3, -3, -3, -3, -4, -4, -4, -5, -5, -5 } local POSES = {} local function pose(s, par) local key = s * 2 + par local p = POSES[key] if p then return p end p = { rows = {}, tail = {} } for i = 1, 10 do local e = floor(EXT[s + 1] * ((i - 1) / 9) ^ 1.4 + 0.5) if s >= 3 and i >= 6 then e = e + ((i + par) % 2 == 0 and 1 or 0) end local rr = RR[i] - ((s >= 3 and i >= 7) and 1 or 0) p.rows[i] = { 37 + i, LB[i] - e, rr } end if s == 0 then p.tail = { { -3, 38 }, { -3, 39 }, { -3, 40 } } else local L = ({ 0, 3, 5, 7 })[min(s, 4)] if s == 1 then L = 2 end for i = 1, L do p.tail[i] = { -2 - i, 38 + (s == 1 and floor(i * 0.5) or (s >= 2 and ((floor(i / 2) + par) % 2) or 0)) } end end POSES[key] = p return p end local function figure(s, par) local p = pose(s, par) local x0 = X0 rect(x0 - 1, 33, 4, 1, CAPE[1], CAPE[2], CAPE[3]) rect(x0 - 2, 34, 5, 4, CAPE[1], CAPE[2], CAPE[3]) rect(x0 - 2, 34, 2, 4, SHADE[1], SHADE[2], SHADE[3]) rect(x0 + 3, 34, 1, 3, SKIN[1], SKIN[2], SKIN[3]) px(x0 + 3, 35, 40, 22, 30) px(x0 + 2, 33, RIM[1], RIM[2], RIM[3]) rect(x0 - 2, 38, 5, 1, SCARF[1], SCARF[2], SCARF[3]) local t = p.tail for i = 1, #t do px(x0 + t[i][1], t[i][2], SCARF[1], SCARF[2], SCARF[3]) end for i = 1, 10 do local r = p.rows[i] local y, a, b = r[1], x0 + r[2], x0 + r[3] if i > 1 then rect(a, y, b - a - 1, 1, CAPE[1], CAPE[2], CAPE[3]) rect(a, y, min(b - a - 1, x0 - 2 - a + 2), 1, SHADE[1], SHADE[2], SHADE[3]) px(b - 1, y, RIM[1], RIM[2], RIM[3]) end end rect(x0 - 2, 48, 2, 2, BOOT[1], BOOT[2], BOOT[3]) rect(x0 + 1, 48, 2, 2, BOOT[1], BOOT[2], BOOT[3]) end local function flower(s, t) local o = floor(-0.55 * s + 1.3 * sin(t * (0.16 + 0.045 * s)) + 0.5) for h = 1, 6 do px(FX + floor(o * (h / 6) ^ 1.4 + 0.5), GROUND - h, 70, 170, 90) end px(FX - 1, GROUND - 2, 70, 170, 90) px(FX + 1, GROUND - 3, 70, 170, 90) local bx, by = FX + o, GROUND - 8 px(bx - 1, by, 250, 110, 170); px(bx + 1, by, 250, 110, 170) px(bx, by - 1, 250, 110, 170); px(bx, by + 1, 250, 110, 170) px(bx, by, 255, 226, 120) end local WS = 1 local function wind(t) local v = (0.5 + 0.3 * sin(t * 0.017) + 0.2 * sin(t * 0.043 + 1.3)) * WS return max(0, min(4, floor(v * 5.2 - 0.6))) end local function clouds(t) local cl = { { 19, 26, 0.03, 4 }, { 29, 18, -0.02, 36 }, { 44, 22, 0.015, 50 } } for i = 1, #cl do local c = cl[i] local x = (c[4] + t * c[3]) % (W + c[2]) - c[2] span(c[1], x + 3, x + c[2] - 3, 120, 140, 210, 0.12) span(c[1] + 1, x, x + c[2], 120, 140, 210, 0.12) end end local function shooting(t) local n, tl = t // 270, t % 270 if tl >= 24 then return end local k = hash32(n * 0x9E3779B1 + 7) local x0, y0 = 30 + umod(k, 17), 2 + umod(k >> 8, 5) local a = min(1, tl / 4, (24 - tl) / 6) for i = 0, 7 do local u = tl - i * 0.9 if u >= 0 then dot(x0 - 2.4 * u, y0 + 1.1 * u, 220, 232, 255, a * (1 - i / 8)) end end end function on_settings() local c = cfg.cloak or { r = 210, g = 38, b = 44 } CAPE = { c.r, c.g, c.b } SHADE = { floor(c.r * 0.55), floor(c.g * 0.55), floor(c.b * 0.55) } RIM = { floor(c.r * 0.6 + 100), floor(c.g * 0.6 + 80), floor(c.b * 0.6 + 100) } WS = ({ calm = 0.55, breeze = 1, gale = 1.35 })[cfg.wind] or 1 end function render() if not BG then build_bg() end gfx.blit_rgb(BG, 0, 0, W, H) local t = frame for i = 1, #STARS do local s = STARS[i] local b = 0.6 + 0.4 * sin(t * 0.07 + s[3]) local v = floor((s[4] and 255 or 190) * b) px(s[1], s[2], v, v, min(255, v + 20)) end for i = 1, #LIGHTS do local l = LIGHTS[i] local b = 0.55 + 0.45 * sin(t * 0.05 + i * 2) px(l[1], l[2], floor(255 * b), floor(200 * b), floor(90 * b)) end clouds(t) if cfg.shoot ~= false then shooting(t) end local s = wind(t) figure(s, (t // 3) % 2) flower(s, t) end