info = { type = "image", title = "Tunnel drift", category = "patterns", author = "BRRRO", version = "1.0", license = "MIT", desc = "Flight through a two-tone square tunnel", api = 33, } local ltr = ({ sk = { ["Palette"] = "Paleta", ["Speed"] = "Rýchlosť", ["Drift"] = "Zákruta", ["Ocean"] = "Oceán", ["Ember"] = "Žiar", ["Dusk"] = "Súmrak" }, cs = { ["Palette"] = "Paleta", ["Speed"] = "Rychlost", ["Drift"] = "Zatáčka", ["Ocean"] = "Oceán", ["Ember"] = "Žár", ["Dusk"] = "Soumrak" }, })[lang] or {} local function LT(s) return ltr[s] or s end settings = { { key = "pal", label = LT("Palette"), type = "int", default = "ocean", opts = { keys = { "ocean", "ember", "dusk" }, LT("Ocean"), LT("Ember"), LT("Dusk") } }, { key = "speed", label = LT("Speed"), type = "int", min = 1, max = 5, default = 3 }, { key = "drift", label = LT("Drift"), type = "int", min = 0, max = 5, default = 3 }, } local rect, blend_rect = gfx.rect, gfx.blend_rect local floor, sin, cos, max, min = math.floor, math.sin, math.cos, math.max, math.min local W, H, FPS = gfx.W, gfx.H, gfx.FPS local TAU = 6.2831853 local PAL = { ocean = { { 96, 138, 232 }, { 168, 232, 160 } }, ember = { { 232, 96, 96 }, { 255, 226, 176 } }, dusk = { { 116, 92, 214 }, { 246, 196, 116 } }, } local CA, CB = PAL.ocean[1], PAL.ocean[2] function on_settings() local p = PAL[cfg.pal] or PAL.ocean CA, CB = p[1], p[2] end local G, H0, NR = 1.28, 2.2, 15 local function square(cx, cy, h, c, a) local l, r, t, b = cx - h, cx + h, cy - h, cy + h local il, ir, it, ib = floor(l), floor(r), floor(t), floor(b) local w, ht = ir - il - 1, ib - it - 1 if w < 1 or ht < 1 then return end if a >= 1 then rect(il + 1, it + 1, w, ht, c[1], c[2], c[3]) else blend_rect(il + 1, it + 1, w, ht, c[1], c[2], c[3], a) end blend_rect(il, it + 1, 1, ht, c[1], c[2], c[3], a * (il + 1 - l)) blend_rect(ir, it + 1, 1, ht, c[1], c[2], c[3], a * (r - ir)) blend_rect(il, it, w + 2, 1, c[1], c[2], c[3], a * (it + 1 - t)) blend_rect(il, ib, w + 2, 1, c[1], c[2], c[3], a * (b - ib)) end function render() local t = frame / FPS local pos = t * 0.35 * (cfg.speed or 3) local base = floor(pos) local ph = pos - base local D = 3.6 * (cfg.drift or 3) local turn = TAU * t / 14 gfx.clear(CA[1], CA[2], CA[3]) for i = NR, 0, -1 do local j = i + ph local h = H0 * G ^ j local f = max(0, 1 - h / 48) local a = turn - 0.03 * j local c = (i + base) % 2 == 0 and CA or CB square(32 + D * f * cos(a), 32 + D * f * sin(a), h, c, i == 0 and ph or 1) end end