info = { type = "image", title = "CRT code", category = "other", author = "BRRRO", version = "1.0", license = "MIT", desc = "Code types itself on an old CRT in a dark room", api = 33, } local tr = ({ sk = { ["Colours"] = "Farby", ["green"] = "zelená", ["amber"] = "jantárová", ["ice"] = "ľad", ["Typing speed"] = "Rýchlosť písania", ["Scanlines"] = "Riadky obrazu" }, cs = { ["Colours"] = "Barvy", ["green"] = "zelená", ["amber"] = "jantarová", ["ice"] = "led", ["Typing speed"] = "Rychlost psaní", ["Scanlines"] = "Řádky obrazu" }, })[lang] or {} local function T(s) return tr[s] or s end settings = { { key = "theme", label = T("Colours"), type = "int", default = 0, opts = { T("syntax"), T("green"), T("amber"), T("ice") } }, { key = "speed", label = T("Typing speed"), type = "int", min = 1, max = 5, default = 3 }, { key = "scan", label = T("Scanlines"), type = "bool", default = true }, } local rect, px, blend_rect = gfx.rect, gfx.px, gfx.blend_rect local floor, sin = math.floor, math.sin local hash32 = math.hash32 local W, H, FPS = gfx.W, gfx.H, gfx.FPS local STEP_HZ = 30 local WALL = { 10, 12, 26 } local BODY, BODY_L, BODY_D = { 44, 50, 68 }, { 70, 78, 102 }, { 28, 32, 46 } local RING = { 20, 24, 36 } local DESK, DESK_L, DESK_D = { 70, 46, 36 }, { 98, 64, 46 }, { 48, 32, 28 } local KB, KEY = { 56, 60, 78 }, { 92, 100, 126 } local MUG, MUG_D = { 186, 190, 204 }, { 130, 134, 152 } local THEMES = { { { { 255, 104, 176 }, { 110, 230, 255 }, { 255, 214, 96 }, { 255, 150, 70 }, { 120, 132, 176 } }, { 8, 14, 34 }, { 110, 230, 255 } }, { { { 80, 255, 120 }, { 50, 200, 90 }, { 120, 255, 160 }, { 36, 150, 72 }, { 30, 110, 56 } }, { 6, 28, 18 }, { 60, 240, 110 } }, { { { 255, 190, 60 }, { 224, 150, 40 }, { 255, 220, 120 }, { 176, 110, 30 }, { 126, 82, 24 } }, { 34, 18, 6 }, { 255, 170, 50 } }, { { { 210, 244, 255 }, { 120, 200, 240 }, { 255, 255, 255 }, { 90, 150, 204 }, { 62, 104, 156 } }, { 8, 24, 40 }, { 120, 210, 255 } }, } local TH = THEMES[1] local SX, SY, SW, SH = 10, 9, 44, 32 local LX = 12 local PITCH = 4 local NLINES = 24 local LINES, LTOT = {}, {} for n = 1, NLINES do local h = hash32(n * 0x9E3779B1) local indent = ((h >> 3) & 0x7FFF) % 3 local toks, x = {}, indent * 3 local nt = 2 + ((h >> 6) & 3) for k = 1, nt do local hk = hash32(n * 7919 + k * 104729) & 0x7FFF local len = 2 + hk % 7 local kind = k == 1 and (hk % 3 == 0 and 1 or 2) or (1 + (hk >> 4) % 5) if x + len > 40 then break end toks[#toks + 1] = { kind, len, x } x = x + len + 2 end if n % 7 == 0 then toks = { { 5, 6 + (h & 7), indent * 3 } } ; x = indent * 3 + toks[1][2] + 2 end LINES[n], LTOT[n] = toks, x - 2 end local BG = nil local SPD, CUM, CYCLE = 1.35, {}, 1 function on_settings() TH = THEMES[(cfg.theme or 0) + 1] or THEMES[1] SPD = 0.45 * (cfg.speed or 3) local t = 0 for n = 1, NLINES do t = t + floor(LTOT[n] / SPD) + 12 CUM[n] = t end CYCLE = t BG = nil end local function build_bg() local ink = TH[3] rect(0, 0, W, H, WALL[1], WALL[2], WALL[3]) blend_rect(0, 0, W, 52, ink[1], ink[2], ink[3], 0.10) blend_rect(2, 1, 60, 49, ink[1], ink[2], ink[3], 0.10) rect(0, 50, W, 14, DESK[1], DESK[2], DESK[3]) rect(0, 50, W, 1, DESK_L[1], DESK_L[2], DESK_L[3]) rect(0, 62, W, 2, DESK_D[1], DESK_D[2], DESK_D[3]) blend_rect(0, 50, W, 14, ink[1], ink[2], ink[3], 0.07) rect(25, 45, 14, 4, 34, 38, 52) rect(19, 48, 26, 2, 30, 34, 46) rect(6, 5, 52, 41, BODY[1], BODY[2], BODY[3]) rect(6, 5, 52, 1, BODY_L[1], BODY_L[2], BODY_L[3]) rect(6, 5, 1, 40, BODY_L[1], BODY_L[2], BODY_L[3]) rect(6, 44, 52, 2, BODY_D[1], BODY_D[2], BODY_D[3]) rect(57, 6, 1, 40, BODY_D[1], BODY_D[2], BODY_D[3]) rect(9, 8, 46, 34, RING[1], RING[2], RING[3]) rect(44, 43, 3, 1, BODY_L[1], BODY_L[2], BODY_L[3]) rect(25, 43, 6, 1, 84, 92, 116) rect(55, 13, 2, 3, 255, 226, 90) px(55, 14, 190, 150, 50) rect(8, 52, 41, 10, KB[1], KB[2], KB[3]) for r = 0, 2 do for c = 0, 9 do rect(9 + c * 4 + (r % 2) * 1, 53 + r * 3, 3, 2, KEY[1], KEY[2], KEY[3]) end end rect(52, 53, 6, 7, MUG[1], MUG[2], MUG[3]) rect(52, 58, 6, 2, MUG_D[1], MUG_D[2], MUG_D[3]) rect(58, 54, 1, 3, MUG_D[1], MUG_D[2], MUG_D[3]) rect(53, 54, 4, 1, 90, 56, 40) BG = gfx.snapshot(0, 0, W, H) end function render() if not BG then build_bg() end local f = frame * STEP_HZ // FPS gfx.blit_rgb(BG, 0, 0, W, H) local COL, SB, ink = TH[1], TH[2], TH[3] rect(SX, SY, SW, SH, SB[1], SB[2], SB[3]) local t = f % CYCLE local k = 1 while CUM[k] <= t do k = k + 1 end local lt = t - (k > 1 and CUM[k - 1] or 0) local tw = lt * SPD local sc = lt < 5 and floor(PITCH * (1 - lt / 5) + 0.5) or 0 gfx.clip(SX, SY, SW, SH) local cx, cy = LX, 0 for r = -1, 7 do local n = (k - 1 - (7 - r)) % NLINES + 1 local y = SY + 2 + r * PITCH + sc local toks = LINES[n] local lim = r == 7 and tw or 999 for i = 1, #toks do local tk = toks[i] local x0 = tk[3] local w = tk[2] if lim < x0 + w then w = floor(lim - x0 + 0.5) end if w > 0 then local c = COL[tk[1]] rect(LX + x0, y, w, 2, c[1], c[2], c[3]) end if lim < x0 + tk[2] then break end end if r == 7 then local typed = tw < LTOT[n] and tw or LTOT[n] cx, cy = LX + floor(typed + 0.5) + 1, y end end if tw < LTOT[(k - 1 + 0) % NLINES + 1] or (f // 8) % 2 == 0 then rect(cx, cy - 1, 2, 4, ink[1], ink[2], ink[3]) end if cfg.scan ~= false then for y = SY, SY + SH - 1, 2 do blend_rect(SX, y, SW, 1, 0, 0, 0, 0.30) end end local by = SY - 6 + floor((f * 0.4) % (SH + 12)) for i = 0, 3 do local y = by + i if y >= SY and y < SY + SH then blend_rect(SX, y, SW, 1, ink[1], ink[2], ink[3], i == 1 and 0.12 or 0.07) end end if f % 211 < 3 then blend_rect(SX, SY, SW, SH, 255, 255, 255, 0.06) end blend_rect(SX + 2, SY + 1, 7, 1, 255, 255, 255, 0.10) blend_rect(SX + 2, SY + 2, 1, 4, 255, 255, 255, 0.10) gfx.clip() px(SX, SY, RING[1], RING[2], RING[3]); px(SX + SW - 1, SY, RING[1], RING[2], RING[3]) px(SX, SY + SH - 1, RING[1], RING[2], RING[3]); px(SX + SW - 1, SY + SH - 1, RING[1], RING[2], RING[3]) local pw = 0.55 + 0.45 * sin(f * 0.05) rect(50, 43, 2, 1, floor(30 + 40 * pw), floor(150 + 105 * pw), floor(60 + 60 * pw)) local typing = tw < LTOT[(k - 1) % NLINES + 1] if typing and (hash32((f // 2) * 0x9E3779B1) & 3) ~= 0 then rect(53, 43, 2, 1, 255, 170, 40) else rect(53, 43, 2, 1, 70, 44, 20) end if typing then local idx = hash32((floor(tw / 2) + k * 31) * 0x85EBCA6B) & 0x7FFF idx = idx % 30 local r, c = idx // 10, idx % 10 rect(9 + c * 4 + (r % 2), 53 + r * 3, 3, 2, 224, 230, 255) end for i = 0, 2 do local u = ((f * 0.15 + i * 3.3) % 10) / 10 blend_rect(54 + floor(i + 1.4 * sin(f * 0.07 + i * 2 + u * 6)), 51 - floor(u * 6), 1, 1, 220, 230, 245, 0.45 * (1 - u)) end end