info = { type = "image", title = "Neon Anubis", category = "characters", author = "BRRRO", version = "1.0", license = "MIT", desc = "A neon jackal-headed god with a blinking eye", api = 44, } local tr = ({ sk = { ["Neon colour"] = "Farba neónu", ["cycle"] = "cyklus", ["cyan"] = "azúrová", ["magenta"] = "purpurová", ["gold"] = "zlatá", ["Flicker"] = "Blikanie", ["off"] = "vypnuté", ["rare"] = "zriedka", ["often"] = "často" }, cs = { ["Neon colour"] = "Barva neonu", ["cycle"] = "cyklus", ["cyan"] = "azurová", ["magenta"] = "purpurová", ["gold"] = "zlatá", ["Flicker"] = "Blikání", ["off"] = "vypnuto", ["rare"] = "zřídka", ["often"] = "často" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "hue", label = T("Neon colour"), type = "int", default = 0, opts = { T("cycle"), T("cyan"), T("magenta"), T("gold") } }, { key = "flicker", label = T("Flicker"), type = "int", default = 1, opts = { T("off"), T("rare"), T("often") } }, } local rect, px = gfx.rect, gfx.px local floor, sin, cos, abs, sqrt = math.floor, math.sin, math.cos, math.abs, math.sqrt local hash32 = math.hash32 local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local function c3(c) return c[1], c[2], c[3] end local function ell(cx, cy, rx, ry, c) for y = floor(cy - ry + 0.5), floor(cy + ry - 0.5) do local dy = (y + 0.5 - cy) / ry local k = 1 - dy * dy if k > 0 then local hw = rx * sqrt(k) local x0 = floor(cx - hw + 0.5) rect(x0, y, floor(cx + hw + 0.5) - x0, 1, c[1], c[2], c[3]) end end end local NIGHT1, NIGHT2, NIGHT3 = { 16, 22, 78 }, { 24, 32, 104 }, { 34, 44, 128 } local SUN, SUN2 = { 40, 52, 140 }, { 50, 64, 156 } local PYR, PYR_L = { 30, 40, 116 }, { 58, 74, 170 } local GLYPH = { 86, 104, 196 } local BG = nil local function build_bg() rect(0, 0, W, 22, c3(NIGHT1)); rect(0, 22, W, 22, c3(NIGHT2)); rect(0, 44, W, 20, c3(NIGHT3)) for x = 0, W - 1, 2 do px(x, 21, c3(NIGHT2)); px(x + 1, 43, c3(NIGHT3)) end ell(36, 28, 25, 25, SUN); ell(36, 28, 21, 21, SUN2) for y = 40, 63 do local w = (y - 40) * 12 // 24 + 1 rect(50 - w, y, 2 * w, 1, c3(PYR)) px(50 - w, y, c3(PYR_L)) end ell(7.5, 6.5, 2.6, 3.2, GLYPH); ell(7.5, 6.5, 1.0, 1.6, NIGHT1) rect(7, 9, 2, 8, c3(GLYPH)); rect(4, 11, 8, 2, c3(GLYPH)) for i = 0, 3 do px(3 + i * 4, 60, c3(GLYPH)); px(5 + i * 4, 61, c3(GLYPH)) end rect(54, 5, 5, 1, c3(GLYPH)); px(53, 6, c3(GLYPH)); px(59, 6, c3(GLYPH)); rect(55, 7, 3, 1, c3(GLYPH)) px(56, 6, 255, 255, 255) BG = gfx.snapshot(0, 0, W, H) end local CW, CH = 60, 64 local grid local function cp(x, y, v) if x >= 0 and y >= 0 and x < CW and y < CH then grid[y][x + 1] = v end end local function cg(x, y) if x < 0 or y < 0 or x >= CW or y >= CH then return 0 end return grid[y][x + 1] end local EDGE_N, EDGE_X, EDGE_Y = 0, {}, {} local function ln(x0, y0, x1, y1, v, only) local dx, dy = abs(x1 - x0), -abs(y1 - y0) local sx, sy = x0 < x1 and 1 or -1, y0 < y1 and 1 or -1 local e = dx + dy while true do if not only or cg(x0, y0) == only then cp(x0, y0, v) if v == 1 then EDGE_N = EDGE_N + 1; EDGE_X[EDGE_N] = x0; EDGE_Y[EDGE_N] = y0 end end if x0 == x1 and y0 == y1 then break end local e2 = 2 * e if e2 >= dy then e = e + dy; x0 = x0 + sx end if e2 <= dx then e = e + dx; y0 = y0 + sy end end end local function pline(pts, v, closed) for i = 1, #pts - 2, 2 do ln(pts[i], pts[i + 1], pts[i + 2], pts[i + 3], v) end if closed then ln(pts[#pts - 1], pts[#pts], pts[1], pts[2], v) end end local function pfill(pts, v) local n = #pts // 2 local ymin, ymax = 1e9, -1e9 for i = 1, n do local y = pts[i * 2]; if y < ymin then ymin = y end; if y > ymax then ymax = y end end for y = ymin, ymax do local xs = {} for i = 1, n do local j = i % n + 1 local xa, ya, xb, yb = pts[i * 2 - 1], pts[i * 2], pts[j * 2 - 1], pts[j * 2] if ya ~= yb then local lo, hi = ya < yb and ya or yb, ya < yb and yb or ya if y + 0.5 >= lo and y + 0.5 < hi then xs[#xs + 1] = xa + (y + 0.5 - ya) * (xb - xa) / (yb - ya) end end end table.sort(xs) for k = 1, #xs - 1, 2 do for x = floor(xs[k] + 0.5), floor(xs[k + 1] - 0.5) do cp(x, y, v) end end end end local HEAD = { 3,23, 5,21, 18,17, 21,15, 24,2, 29,13, 30,14, 34,3, 39,16, 43,20, 46,27, 47,38, 43,49, 36,55, 24,48, 22,37, 18,32, 5,29, 4,27, 2,25 } local function build_neon() grid = {} for y = 0, CH - 1 do local row = {} for x = 1, CW do row[x] = 0 end grid[y] = row end pfill(HEAD, 4) ln(25, 5, 26, 12, 2); ln(33, 7, 35, 13, 2) ln(5, 29, 20, 30, 2); ln(20, 30, 22, 29, 2) ln(6, 28, 12, 27, 2) for i = 0, 6 do ln(26 + i * 3, 19 + i * 2 - 6, 46, 26 + i * 4 - 4, 2, 4) end ln(24, 33, 30, 38, 2); ln(30, 38, 34, 46, 2) for b, r in ipairs({ 11, 16, 21 }) do local px0, py0 = 32 - r, 64 for t = 1, 12 do local a = t * 15 * 0.017453 local x1, y1 = floor(32 - r * cos(a) + 0.5), floor(64 - r * sin(a) + 0.5) ln(px0, py0, x1, y1, b == 3 and 1 or 2) px0, py0 = x1, y1 end end for t = 1, 11 do local a = t * 15 * 0.017453 ln(floor(32 - 11 * cos(a) + 0.5), floor(64 - 11 * sin(a) + 0.5), floor(32 - 21 * cos(a) + 0.5), floor(64 - 21 * sin(a) + 0.5), 2) end pline(HEAD, 1, true) ln(20, 21, 24, 19, 1); ln(24, 19, 28, 21, 1); ln(20, 21, 24, 22, 2); ln(24, 22, 28, 21, 2) end local function build_neon2() for i = 1, EDGE_N do local x, y = EDGE_X[i], EDGE_Y[i] for d = 1, 4 do local nx, ny = x + (d == 1 and -1 or (d == 2 and 1 or 0)), y + (d == 3 and -1 or (d == 4 and 1 or 0)) local v = cg(nx, ny) if (v == 0 or v == 4) and nx >= 0 and nx < CW and ny >= 0 and ny < CH then grid[ny][nx + 1] = 3 end end end local t = {} for y = 0, CH - 1 do t[#t + 1] = string.char(table.unpack(grid[y])) end grid = table.concat(t) end local PAL = { 0, 0, 0, 255, 255, 255, 255, 255, 255, 120, 120, 120, 60, 60, 60, 255, 255, 255 } local function hsv(h, s, v) local c = v * s local hp = (h % 360) / 60 local x = c * (1 - abs(hp % 2 - 1)) local r, g, b if hp < 1 then r, g, b = c, x, 0 elseif hp < 2 then r, g, b = x, c, 0 elseif hp < 3 then r, g, b = 0, c, x elseif hp < 4 then r, g, b = 0, x, c elseif hp < 5 then r, g, b = x, 0, c else r, g, b = c, 0, x end local m = v - c return floor((r + m) * 255 + 0.5), floor((g + m) * 255 + 0.5), floor((b + m) * 255 + 0.5) end local function setpal(i, h, s, v) PAL[i * 3 + 1], PAL[i * 3 + 2], PAL[i * 3 + 3] = hsv(h, s, v) end local EYE_X, EYE_Y = 24, 20 local STAGE = 0 function render() if STAGE == 0 then build_bg(); STAGE = 1 elseif STAGE == 1 then build_neon(); STAGE = 2 elseif STAGE == 2 then build_neon2(); STAGE = 3 end gfx.blit_rgb(BG, 0, 0, W, H) if STAGE < 3 then gfx.ready(false) return end local f = frame * STEP_HZ // FPS local mode = cfg.hue or 0 local h if mode == 0 then local ph = (f % 600) / 300 if ph > 1 then ph = 2 - ph end ph = ph * ph * (3 - 2 * ph) ph = ph * ph * (3 - 2 * ph) h = 175 + 150 * ph elseif mode == 1 then h = 175 elseif mode == 2 then h = 320 else h = 42 end local k = 1 local fl = cfg.flicker or 1 if fl > 0 then local win = f // 80 local r = hash32(win * 7919 + 13) & 7 local u = f % 80 if r < (fl == 2 and 3 or 1) and u < 10 and (u // 2) % 2 == 0 then k = 0.42 end end local bl = 1 - abs(h - 240) / 55 if bl < 0 then bl = 0 end setpal(1, h, 0.55 - 0.3 * bl, k) setpal(2, h, 0.85 - 0.3 * bl, (0.82 + 0.18 * bl) * k) setpal(3, h, 1.0, 0.42 * k) setpal(4, h, 1.0, 0.26 * k) gfx.blit_indexed(grid, PAL, 4, 0, CW, CH, CW, CH, true) local ex, ey = EYE_X + 4, EYE_Y local cyc = f % 150 local blink = cyc >= 100 and cyc < 104 local glow = 0.5 + 0.5 * sin(f * 0.13) if blink then rect(ex - 4, ey - 1, 9, 1, hsv(h, 0.4, 0.55 * k)) else local br = floor(150 + 105 * glow) local r, g, b = hsv(h, 0.15, 1) rect(ex - 1, ey - 1, 3, 3, floor(r * br / 255), floor(g * br / 255), floor(b * br / 255)) px(ex, ey, 255, 255, 255) if glow > 0.7 then local r2, g2, b2 = hsv(h, 0.8, 0.85 * k) px(ex - 2, ey, r2, g2, b2); px(ex + 2, ey, r2, g2, b2); px(ex, ey - 2, r2, g2, b2) end end end