info = { type = "image", title = "Psychedelic owl", category = "patterns", author = "BRRRO", version = "1.0", license = "MIT", desc = "Colour-cycling owl face with glowing eyes", api = 33, } local tr = ({ sk = { ["Speed"] = "Rýchlosť", ["Palette"] = "Paleta", ["neon"] = "neón", ["fire"] = "oheň", ["ocean"] = "oceán", ["candy"] = "cukrík", ["Ripple"] = "Vlnky", ["Eyes"] = "Oči" }, cs = { ["Speed"] = "Rychlost", ["Palette"] = "Paleta", ["fire"] = "oheň", ["ocean"] = "oceán", ["candy"] = "bonbon", ["Ripple"] = "Vlnky", ["Eyes"] = "Oči" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "speed", label = T("Speed"), type = "int", min = 1, max = 8, default = 4 }, { key = "pal", label = T("Palette"), type = "int", default = 0, opts = { T("neon"), T("fire"), T("ocean"), T("candy") } }, { key = "wave", label = T("Ripple"), type = "bool", default = true }, { key = "eye", label = T("Eyes"), type = "color", default = "#FFB020" }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local floor, sin, sqrt, abs = math.floor, math.sin, math.sqrt, math.abs local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local TAU = 6.2831853 local N = 72 local N3 = N * 3 local IDX_DARK, IDX_BEAK, IDX_SPARK, IDX_GLOW1, IDX_GLOW2 = N, N + 1, N + 2, N + 3, N + 4 local IDX_EO, IDX_EYE, IDX_EYEH = N + 5, N + 6, N + 7 local function hsv(h, s, v) h = (h % 360) / 60 local i = floor(h) local f = h - i local p, q, t = v * (1 - s), v * (1 - s * f), v * (1 - s * (1 - f)) local r, g, b if i == 0 then r, g, b = v, t, p elseif i == 1 then r, g, b = q, v, p elseif i == 2 then r, g, b = p, v, t elseif i == 3 then r, g, b = p, q, v elseif i == 4 then r, g, b = t, p, v else r, g, b = v, p, q end return floor(r * 255 + 0.5), floor(g * 255 + 0.5), floor(b * 255 + 0.5) end local function pal_color(kind, k) local u = k / N local v = 0.72 + 0.28 * (0.5 + 0.5 * sin(u * TAU * 3)) if kind == 0 then return hsv(200 + 360 * u, 1, v) elseif kind == 1 then return hsv(340 + 80 * (0.5 - 0.5 * math.cos(u * TAU)), 1, v) elseif kind == 2 then return hsv(150 + 120 * (0.5 - 0.5 * math.cos(u * TAU)), 0.9, v) else return hsv(360 * u, 0.6, 0.85 + 0.15 * sin(u * TAU * 3)) end end local BASE, OUT = {}, {} local function build_pal(kind) for k = 0, N - 1 do local r, g, b = pal_color(kind, k) BASE[3 * k + 1], BASE[3 * k + 2], BASE[3 * k + 3] = r, g, b end for i = 1, N3 + 24 do OUT[i] = 0 end end local GRID = nil local GROWS = {} local function build_grid(y0, y1) local half = {} for y = y0, y1 do local dy2 = 2 * y - 47 for x = 0, 31 do local dx2 = 63 - 2 * x local c local ex2 = dx2 - 24 local d2 = ex2 * ex2 + dy2 * dy2 local bw = 3.8 - (y - 26) * 0.19 local dx = dx2 / 2 if y >= 26 and y < 46 and dx < bw + 1.2 then c = (dx < bw) and IDX_BEAK or IDX_DARK elseif d2 < 41 * 41 then local d = sqrt(d2) / 2 if d < 4.6 then c = IDX_EYEH elseif d < 6.2 then c = IDX_EYE elseif d < 8 then c = IDX_EO elseif d < 9 then c = IDX_DARK elseif d < 11 then c = IDX_GLOW1 elseif d < 12.5 then c = IDX_DARK elseif d < 14 then c = IDX_GLOW2 elseif d < 15 then c = IDX_DARK else c = (floor(d * 3) * 2) % N end if d >= 15 and floor(d * 3) % 5 == 0 then c = IDX_DARK end else local v1 = 2 * y + dx2 local b = v1 // 12 local o = v1 % 12 local sh = dx2 + b * 8 local k = sh // 8 if o < 2 then c = IDX_DARK elseif sh % 8 < 2 and o < 9 then c = IDX_DARK else c = (b * 10 + k * 14 + (o >> 2) * 4 + ((b * 37 + k * 91 + b * k * 7) & 3) * 3) % N end if (x * 7 + y * 13 + x * y) % 53 == 0 then c = IDX_SPARK end end half[x + 1] = c end local s = string.char(table.unpack(half, 1, 32)) GROWS[y + 1] = s .. s:reverse() end if y1 == 63 then GRID = table.concat(GROWS) end end local EYE_R, EYE_G, EYE_B = 255, 176, 32 local PAL_KIND, SPEED, WAVE = 0, 4, true function on_settings() local c = cfg.eye or { r = 255, g = 176, b = 32 } EYE_R, EYE_G, EYE_B = c.r, c.g, c.b SPEED = cfg.speed or 4 WAVE = cfg.wave ~= false local k = cfg.pal or 0 if k ~= PAL_KIND or #BASE == 0 then PAL_KIND = k build_pal(k) end end local function span(xa, xb, y, r, g, b) if xb - xa <= 0.05 then return end local ia, ib = floor(xa), floor(xb) if ia == ib then blend(ia, y, r, g, b, xb - xa) return end local a0 = ia if xa - ia > 0.03 then blend(ia, y, r, g, b, 1 - (xa - ia)) a0 = ia + 1 end if xb - ib > 0.03 then blend(ib, y, r, g, b, xb - ib) end if ib > a0 then rect(a0, y, ib - a0, 1, r, g, b) end end local function ell(cx, cy, rx, ry, r, g, b) for y = floor(cy - ry), floor(cy + ry) do local dy = y + 0.5 - cy local q = 1 - (dy * dy) / (ry * ry) if q > 0 then local h = rx * sqrt(q); span(cx - h, cx + h, y, r, g, b) end end end local function eye(cx, cy, gx, gy, lid) ell(cx + gx, cy + gy, 3.0, 3.4, 10, 6, 30) px(floor(cx + gx - 1), floor(cy + gy - 2), 255, 255, 255) if lid > 0.02 then local ly = cy - 9 + 18 * lid for y = floor(cy - 9), floor(ly) do local dy = y + 0.5 - cy local s = 81 - dy * dy if s > 0 and y + 0.5 < ly then local h = sqrt(s); span(cx - h, cx + h, y, 70, 24, 130) end end local lyi = floor(ly) local dy = lyi + 0.5 - cy local s = 81 - dy * dy if s > 0 then local h = sqrt(s); span(cx - h, cx + h, lyi, 255, 120, 40) end end end function render() if not GRID then if #GROWS == 0 then build_grid(0, 31) else build_grid(32, 63) end return end local t = frame * STEP_HZ // FPS local sh = floor(t * SPEED * 3 / STEP_HZ) % N local s3 = 3 * sh table.move(BASE, s3 + 1, N3, 1, OUT) if s3 > 0 then table.move(BASE, 1, s3, N3 - s3 + 1, OUT) end local p = 0.55 + 0.45 * sin(t * 0.13) local p2 = 0.55 + 0.45 * sin(t * 0.13 + 2.1) OUT[N3 + 1], OUT[N3 + 2], OUT[N3 + 3] = 14, 8, 60 local bp = 0.7 + 0.3 * sin(t * 0.09) OUT[N3 + 4], OUT[N3 + 5], OUT[N3 + 6] = floor(120 + 135 * bp), floor(200 + 55 * bp), 255 local sp = 0.5 + 0.5 * sin(t * 0.31) OUT[N3 + 7], OUT[N3 + 8], OUT[N3 + 9] = floor(200 + 55 * sp), floor(200 + 55 * sp), 255 OUT[N3 + 10], OUT[N3 + 11], OUT[N3 + 12] = floor(EYE_R * (0.45 + 0.55 * p)), floor(EYE_G * (0.45 + 0.55 * p)), floor(EYE_B * (0.45 + 0.55 * p)) OUT[N3 + 13], OUT[N3 + 14], OUT[N3 + 15] = floor(EYE_R * (0.45 + 0.55 * p2)), floor(EYE_G * (0.45 + 0.55 * p2)), floor(EYE_B * (0.45 + 0.55 * p2)) local R, G, B = EYE_R, EYE_G, EYE_B OUT[N3 + 16], OUT[N3 + 17], OUT[N3 + 18] = R, floor(G * 0.55), floor(B * 0.3) OUT[N3 + 19], OUT[N3 + 20], OUT[N3 + 21] = R, G, B OUT[N3 + 22], OUT[N3 + 23], OUT[N3 + 24] = 255, 240, 170 gfx.blit_indexed(GRID, OUT, 0, 0, 64, 64, 64, 64) if WAVE then for k = 0, 1 do local y0 = floor((t * 0.55 + k * 36) % 70) - 6 if y0 >= 0 and y0 <= 58 then local ox = floor(1.6 * sin(t * 0.21 + k * 2) + 0.5) if ox ~= 0 then gfx.blit_indexed(GRID:sub(y0 * 64 + 1, (y0 + 6) * 64), OUT, ox, y0, 64, 6, 64, 6) end end end end local gx, gy = 1.6 * sin(t * 0.04), 1.2 * sin(t * 0.027 + 1) local lid = 0 local d = t % 140 - 100 if d >= 0 and d < 7 then lid = d < 2 and d / 2 or (d < 4 and 1 or 1 - (d - 4) / 3) end eye(20, 24, gx, gy, lid) eye(44, 24, gx, gy, lid) end