info = { type = "image", title = "Vapor room", category = "city", author = "BRRRO", version = "1.0", license = "MIT", desc = "Vaporwave room with a CRT, palm and neon grid", api = 33, } local tr = ({ sk = { ["Grid speed"] = "Rýchlosť mriežky", ["VHS glitches"] = "VHS pruhy", ["TV screen"] = "Obrazovka", ["Auto"] = "Automaticky", ["Static"] = "Šum", ["Bars"] = "Pruhy" }, cs = { ["Grid speed"] = "Rychlost mřížky", ["VHS glitches"] = "VHS pruhy", ["TV screen"] = "Obrazovka", ["Auto"] = "Automaticky", ["Static"] = "Šum", ["Bars"] = "Pruhy" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "grid", label = T("Grid speed"), type = "int", min = 0, max = 3, default = 1 }, { key = "vhs", label = T("VHS glitches"), type = "bool", default = true }, { key = "tv", label = T("TV screen"), type = "int", default = "auto", opts = { keys = { "auto", "static", "bars" }, T("Auto"), T("Static"), T("Bars") } }, } local rect, px, blend, blend_rect = gfx.rect, gfx.px, gfx.blend, gfx.blend_rect local blit, blit_rgb, snapshot = gfx.blit_indexed, gfx.blit_rgb, gfx.snapshot local floor, ceil, sin, cos, sqrt, min, max = math.floor, math.ceil, math.sin, math.cos, math.sqrt, math.min, math.max local hash32, umod = math.hash32, math.umod local char, unpack, concat = string.char, table.unpack, table.concat local W, H = gfx.W, gfx.H local TAU = 6.28318 local KR, KG, KB = 1, 2, 3 local function line(x0, y0, x1, y1, r, g, b) local n = max(math.abs(x1 - x0), math.abs(y1 - y0)) for i = 0, n do px(floor(x0 + (x1 - x0) * i / n + 0.5), floor(y0 + (y1 - y0) * i / n + 0.5), r, g, b) end end local WX, WY, WW, WH = 38, 4, 22, 23 local HOR = 21 local SUNX, SUNY, SUNR = 48.5, 18, 7.5 local function sky(y) local t = (y - WY) / (HOR - WY) return floor(88 + 167 * t), floor(34 + 90 * t), floor(170 - 22 * t) end local function stage_room() for y = 0, 37 do local t = y / 37 rect(0, y, W, 1, floor(58 + 112 * t), floor(22 + 26 * t), floor(112 + 50 * t)) end rect(0, 38, W, 2, 64, 226, 226) for y = 40, H - 1 do local t = (y - 40) / (H - 41) rect(0, y, W, 1, floor(112 - 56 * t), floor(34 - 14 * t), floor(150 - 48 * t)) end for k = -4, 4 do for y = 41, H - 1 do px(floor(32 + k * 13 * (y - 22) / (H - 1 - 22) + 0.5), y, 64, 226, 226) end end blend_rect(0, 40, W, 3, 255, 150, 230, 0.2) rect(WX - 1, WY - 1, WW + 2, WH + 2, 64, 226, 226) for y = WY, HOR - 1 do rect(WX, y, WW, 1, sky(y)) end rect(WX, HOR, WW, 1, 255, 190, 130) for y = HOR + 1, WY + WH - 1 do local t = (y - HOR) / (WY + WH - HOR) rect(WX, y, WW, 1, floor(70 - 30 * t), floor(24 - 8 * t), floor(120 - 14 * t)) end rect(WX - 3, WY + WH + 1, WW + 6, 2, 255, 110, 190) rect(WX - 3, WY + WH + 3, WW + 6, 1, 150, 40, 130) blend_rect(1, 45, 30, 2, 12, 0, 30, 0.35) blend_rect(41, 62, 22, 2, 12, 0, 30, 0.35) end local function stage_objects() gfx.clear(KR, KG, KB) rect(3, 38, 26, 7, 255, 110, 190) rect(3, 38, 26, 1, 255, 178, 228) rect(3, 44, 26, 1, 64, 226, 226) rect(2, 13, 28, 25, 96, 60, 140) rect(3, 14, 26, 23, 190, 152, 218) rect(3, 14, 26, 1, 232, 208, 250) rect(3, 14, 1, 23, 232, 208, 250) rect(3, 36, 26, 1, 150, 112, 182) rect(28, 14, 1, 23, 150, 112, 182) rect(6, 16, 18, 17, 26, 14, 40) rect(25, 18, 3, 3, 64, 226, 226) rect(25, 23, 3, 3, 255, 110, 190) for y = 28, 32, 2 do rect(25, y, 3, 1, 110, 70, 150) end line(12, 13, 6, 4, 64, 226, 226) line(20, 13, 27, 3, 255, 110, 190) px(6, 3, 255, 255, 255); px(27, 2, 255, 255, 255) for y = 41, 52 do local x = 52 + floor((52 - y) * 0.1) rect(x, y, 2, 1, (y % 3 == 0) and 96 or 130, (y % 3 == 0) and 50 or 76, (y % 3 == 0) and 96 or 120) end rect(45, 53, 14, 2, 120, 240, 236) for r = 0, 8 do local w = 12 - r * 4 // 9 local x0 = 52 - w // 2 rect(x0, 55 + r, w, 1, 44, 198, 206) rect(x0 + w - 3, 55 + r, 3, 1, 24, 140, 160) if r == 2 or r == 3 then rect(x0, 55 + r, w, 1, 255, 110, 190) end end rect(46, 52, 12, 1, 70, 36, 84) end local STAGES = { stage_room, stage_objects } local BG, OBJ, STAGE = nil, nil, 1 local PW, PH, CX, CY = 30, 24, 15, 12 local PAL_PALM = { 0, 0, 0, 56, 232, 176, 16, 128, 130, 255, 110, 170 } local FRONDS = { { 10, 12, 0.7 }, { 35, 12, 0.45 }, { 62, 11, 0.25 }, { 90, 9, 0.1 }, { 118, 11, 0.25 }, { 145, 12, 0.45 }, { 170, 12, 0.7 } } local CROWN = {} local function crown(pose) local s = CROWN[pose] if s then return s end local g = {} for i = 1, PW * PH do g[i] = 0 end local sway = (pose - 2) * 0.09 for _, f in ipairs(FRONDS) do local a, len, d = f[1] * 0.01745 + sway, f[2], f[3] for i = 0, len * 2 do local t = i / (len * 2) local x = floor(CX + cos(a) * len * t + 0.5) local y = floor(CY - sin(a) * len * t + d * len * t * t + 0.5) local k = y * PW + x + 1 if x >= 0 and x < PW and y >= 0 and y < PH - 1 then g[k] = 1 if g[k + PW] == 0 then g[k + PW] = 2 end end end end for _, p in ipairs({ { 14, 13 }, { 16, 13 }, { 15, 14 } }) do g[p[2] * PW + p[1] + 1] = 3 end local rows = {} for y = 0, PH - 1 do rows[y + 1] = char(unpack(g, y * PW + 1, y * PW + PW)) end s = concat(rows) CROWN[pose] = s return s end local SW, SH, SX, SY = 16, 15, 7, 17 local PAL_TV = { 0, 0, 0, 24, 14, 48, 74, 52, 124, 64, 200, 210, 255, 100, 190, 246, 240, 255, 236, 236, 248, 250, 232, 110, 64, 226, 226, 90, 230, 140, 255, 100, 200, 255, 80, 110, 80, 100, 255 } local NOISE, BARS = {}, nil local function noise(i) local s = NOISE[i] if s then return s end local t = {} for k = 1, SW * SH do local v = umod(hash32(i * 7919 + k * 0x9E3779B1), 100) t[k] = v < 32 and 1 or (v < 62 and 2 or (v < 76 and 3 or (v < 88 and 4 or 5))) end for _, k in ipairs({ 1, SW, SW * (SH - 1) + 1, SW * SH }) do t[k] = 0 end local rows = {} for y = 0, SH - 1 do rows[y + 1] = char(unpack(t, y * SW + 1, y * SW + SW)) end s = concat(rows) NOISE[i] = s return s end local function bars() if BARS then return BARS end local t = {} for y = 0, SH - 1 do for x = 0, SW - 1 do t[y * SW + x + 1] = y >= SH - 3 and 1 or 5 + x * 7 // SW + 1 end end for _, k in ipairs({ 1, SW, SW * (SH - 1) + 1, SW * SH }) do t[k] = 0 end local rows = {} for y = 0, SH - 1 do rows[y + 1] = char(unpack(t, y * SW + 1, y * SW + SW)) end BARS = concat(rows) return BARS end local COV = {} local function draw_sun(t) for y = 10, HOR - 1 do COV[y] = 0 end for k = 0, 3 do local c = 12.5 + ((k + t / 110) % 4) * 2.4 local th = 0.3 + 0.13 * (c - 11) local lo, hi = c - th / 2, c + th / 2 for y = floor(lo), floor(hi) do if y >= 10 and y < HOR then COV[y] = COV[y] + min(y + 1, hi) - max(y, lo) end end end for y = floor(SUNY - SUNR), HOR - 1 do local dy = y + 0.5 - SUNY if dy * dy < SUNR * SUNR then local hw = sqrt(SUNR * SUNR - dy * dy) local x0 = floor(SUNX - hw + 0.5) local w = floor(SUNX + hw + 0.5) - x0 local u = (y - 10) / 11 rect(x0, y, w, 1, 255, floor(238 - 150 * u), floor(120 + 40 * u)) if COV[y] > 0.02 then local r, g, b = sky(y) blend_rect(x0, y, w, 1, r, g, b, min(1, COV[y])) end end end end local STARS = { { 40, 6 }, { 44, 9 }, { 56, 6 }, { 57, 11 }, { 51, 5 }, { 41, 13 } } function on_settings() STAGE, BG, OBJ = 1, nil, nil end function render() if STAGE <= 2 then if BG then blit_rgb(BG, 0, 0, W, H) end STAGES[STAGE]() if STAGE == 1 then BG = snapshot(0, 0, W, H) else OBJ = snapshot(0, 0, W, H); blit_rgb(BG, 0, 0, W, H); blit_rgb(OBJ, 0, 0, W, H, KR, KG, KB) end STAGE = STAGE + 1 return end local t = frame blit_rgb(BG, 0, 0, W, H) draw_sun(t) for i = 1, #STARS do local s = STARS[i] blend(s[1], s[2], 255, 255, 255, sin(t * 0.07 + i * 2.1) > 0 and 0.8 or 0.3) end local gs = cfg.grid or 1 if gs > 0 then local ph = (t * gs / 150) % 1 for j = 0, 6 do local y = 40.5 + 22.5 * ((j + ph) / 7) ^ 1.8 local y0 = floor(y) local f = y - y0 blend_rect(0, y0, W, 1, 255, 100, 210, 0.85 * (1 - f)) blend_rect(0, y0 + 1, W, 1, 255, 100, 210, 0.85 * f) end end local fl = 0.8 + 0.2 * sin(t * 0.9) blend_rect(4, 45, 24, 1, 100, 230, 240, 0.1 * fl) blend_rect(2, 46, 28, 2, 100, 230, 240, 0.07 * fl) blend_rect(0, 48, 34, 3, 100, 230, 240, 0.045 * fl) blit_rgb(OBJ, 0, 0, W, H, KR, KG, KB) local mode = cfg.tv or "auto" local show_bars = mode == "bars" or (mode == "auto" and t % 600 >= 400 and t % 600 < 520) blit(show_bars and bars() or noise(t // 2 % 6 + 1), PAL_TV, SX, SY, SW, SH, SW, SH, true) local by = SY + (t * 0.35) % SH local by0 = floor(by) local bf = by - by0 blend_rect(SX, by0, SW, 1, 255, 255, 255, 0.2 * (1 - bf)) blend_rect(SX, by0 + 1, SW, 1, 255, 255, 255, 0.2) blend_rect(SX, by0 + 2, SW, 1, 255, 255, 255, 0.2 * bf) blit(crown(2), PAL_PALM, 38, 26, PW, PH, PW, PH, true) if cfg.vhs and t % 540 >= 300 and t % 540 < 342 then local y = floor(63 - (t % 540 - 300) * 1.6) local sh = { 3, -2, 4, -1, 2 } for r = 0, 4 do local yy = y + r if yy >= 0 and yy < H then blit_rgb(snapshot(0, yy, W, 1), sh[r + 1] + (t % 3 - 1), yy, W, 1) end end blend_rect(0, y, W, 5, 64, 226, 236, 0.08) blend_rect(0, y + 5, W, 1, 255, 255, 255, 0.3) for k = 1, 8 do local h = hash32(t * 31 + k) blend(umod(h, W), y + umod(h >> 8, 5), 255, 255, 255, 0.7) end end end