info = { type = "app", title = "Last block", author = "BRRRO", license = "MIT", desc = "Time since the last block", category = "btc", api = 43, } permissions = { "location" } txt = { own = "Own mempool server", own_h = "e.g. http://umbrel.local:3006 - empty = mempool.space", title = "LAST BLOCK", scene = "Scene", scene_o = { "landscape", "blockchain", "mining farm" }, loading = "LOADING", nowifi = "NO WIFI", offline = "OFFLINE", console = "SEE CONSOLE" } for k, v in pairs(({ sk = { own = "Vlastný mempool server", own_h = "napr. http://umbrel.local:3006 - prázdne = mempool.space", title = "POSLEDNY BLOK", scene = "Scéna", scene_o = { "krajina", "reťaz blokov", "ťažobná farma" }, loading = "NACITAVAM", nowifi = "BEZ WIFI", console = "POZRI KONZOLU" }, cs = { own = "Vlastní mempool server", own_h = "např. http://umbrel.local:3006 - prázdné = mempool.space", title = "POSLEDNI BLOK", scene = "Scéna", scene_o = { "krajina", "řetěz bloků", "těžební farma" }, loading = "NACITAM", nowifi = "BEZ WIFI", console = "VIZ KONZOLI" }, })[lang] or {}) do txt[k] = v end settings = { { key = "scene", type = "int", default = "chain", label = txt.scene, opts = { keys = { "land", "chain", "farm" }, table.unpack(txt.scene_o) } }, { key = "node", type = "server", label = txt.own, hint = txt.own_h }, } sources = { hash = { url = "https://mempool.space", limit = 60, own = "node", as = "text", demo = "000000000000000000019a3b6c2d6e5f8a9b1c2d3e4f5a6b7c8d9e0f1a2b3c4d" }, block = { url = "https://mempool.space", limit = 60, own = "node", fields = { "height", "timestamp", "extras.pool.name" }, demo = [[{"height":912345,"timestamp":1774115328,"extras":{"pool":{"name":"Braiins Pool"}}}]] }, } local W, H = gfx.W, gfx.H local px, rect, round_rect, clip = gfx.px, gfx.rect, gfx.round_rect, gfx.clip local blend, blend_rect = gfx.blend, gfx.blend_rect local text, text_center, text_width = gfx.text, gfx.text_center, gfx.text_width local F_SMALL = { font = "3x5" } local F_BIG = { font = "9x15b" } local F_BIG_CELL = { font = "9x15b", cell = true } local CELL = { cell = true } local blit_rgb = gfx.blit_rgb local floor, sin, cos, sqrt, fmod, min = math.floor, math.sin, math.cos, math.sqrt, math.fmod, math.min local hash32, umod = math.hash32, math.umod local fmt, char, concat, upper, sub, find = string.format, string.char, table.concat, string.upper, string.sub, string.find local FPS = gfx.FPS local function lround(v) if v >= 0 then return floor(v + 0.5) else return -floor(-v + 0.5) end end local function mix(ar, ag, ab, br, bg, bb, t) return floor(ar + (br - ar) * t), floor(ag + (bg - ag) * t), floor(ab + (bb - ab) * t) end local CARD_BG = { 238, 230, 210 } local CARD_BRD = { 120, 96, 60 } local DIV_R, DIV_G, DIV_B = 198, 186, 160 local TIT_R, TIT_G, TIT_B = 20, 30, 50 local ACC_R, ACC_G, ACC_B = 30, 40, 70 local POOL_R, POOL_G, POOL_B = 90, 70, 40 local HGT_R, HGT_G, HGT_B = 20, 40, 70 local OK_C, MID_C, LATE_C = { 70, 210, 110 }, { 240, 205, 60 }, { 235, 70, 60 } local GROUND_Y = 15 local CARD_X, CARD_Y, CARD_W, CARD_H = 2, 18, W - 4, 45 local TITLE_Y, CLOCK_Y = 21, 30 local POOL_1, POOL_2A, POOL_2B, POOL_SM = 46, 44, 52, 47 local POOL_MAXW = W - 10 local BLINK_S = 2400 local ADV5 = text_width("AA", F_SMALL) - text_width("A", F_SMALL) local SCENE_H = CARD_Y local SUN_CX, SUN_CY, SUN_R = 56, 6, 6 local SUN_X, SUN_Y, SUN_W, SUN_H = SUN_CX - SUN_R, SUN_CY - SUN_R, 2 * SUN_R + 1, 2 * SUN_R + 1 local LAND = { sky_t = { { 120, 190, 235 }, { 96, 100, 170 }, { 20, 32, 100 } }, sky_b = { { 200, 228, 245 }, { 250, 160, 100 }, { 52, 76, 150 } }, hill = { { 110, 175, 110 }, { 86, 120, 96 }, { 40, 90, 78 } }, ground = { { 80, 150, 90 }, { 66, 104, 80 }, { 32, 72, 60 } }, cloud = { { 255, 250, 232 }, { 250, 196, 170 }, { 90, 104, 146 } }, } local function pal(name, k) local c = LAND[name] if k <= 0.5 then return mix(c[1][1], c[1][2], c[1][3], c[2][1], c[2][2], c[2][3], k * 2) end return mix(c[2][1], c[2][2], c[2][3], c[3][1], c[3][2], c[3][3], (k - 0.5) * 2) end local BTC7 = { "0010100", "1111110", "0110011", "0110011", "0111110", "0110011", "0110011", "1111110", "0010100" } local PUFF = { { 0, 0, 2 }, { 3, 0, 2 }, { -3, 1, 1 } } local HILL = {} for x = 0, W - 1 do HILL[x] = 9 + lround(2 * sin(x * 0.14)) end local STAR_AT = { { 1, 7 }, { 20, 7 }, { 33, 1 }, { 38, 3 }, { 41, 7 }, { 46, 2 }, { 47, 9 }, { 30, 9 } } local land_bg, land_disc, land_stage, land_k, land_stars local function build_land(stage) local k = stage / 5 local moon = k >= 0.5 local tr, tg, tb = pal("sky_t", k) local br_, bg_, bb_ = pal("sky_b", k) local hill, ground, cloud = char(pal("hill", k)), char(pal("ground", k)), char(pal("cloud", k)) local mark = moon and char(96, 106, 134) or char(120, 52, 12) local function at(x, y) if y >= HILL[x] and y < GROUND_Y then return false, hill end for _, p in ipairs(PUFF) do local xx, yy, r = x - (30 + p[1]), y - (4 + p[2]), p[3] if xx * xx + yy * yy <= r * r then return false, cloud end end local bx, by = x - (SUN_CX - 3) + 1, y - (SUN_CY - 4) + 1 if bx >= 1 and bx <= 7 and by >= 1 and by <= 9 and BTC7[by]:sub(bx, bx) == "1" then return false, mark end local dx, dy = x - SUN_CX, y - SUN_CY local dd = sqrt(dx * dx + dy * dy) if dd <= SUN_R then if moon then return true, char(mix(232, 236, 246, 176, 186, 206, dd / SUN_R)) end return true, char(mix(255, 230, 140, 250, 190, 70, dd / SUN_R)) end if y >= GROUND_Y then return false, ground end return false, nil end local none = char(0, 0, 0) local rows, srows = {}, {} for y = 0, SCENE_H - 1 do local row, srow = {}, {} local sky = char(mix(tr, tg, tb, br_, bg_, bb_, y / (GROUND_Y - 1))) for x = 0, W - 1 do local disc, c = at(x, y) row[x + 1] = disc and none or (c or sky) if y >= SUN_Y and y < SUN_Y + SUN_H and x >= SUN_X and x < SUN_X + SUN_W then srow[x - SUN_X + 1] = disc and c or none end end rows[y + 1] = concat(row) if srow[1] then srows[#srows + 1] = concat(srow) end end land_bg, land_disc = concat(rows), concat(srows) land_stars = {} for _, st in ipairs(STAR_AT) do local disc, c = at(st[1], st[2]) if not disc and not c then land_stars[#land_stars + 1] = st end end land_stage, land_k = stage, k LAND.ground_now = { pal("ground", k) } end local function night_k() local tm, sun = data.time, data.sun if not (tm and tm.ok and sun) then return 0 end if sun.polar then return sun.up and 0 or 1 end local h = tm.h + tm.m / 60 local k = 0.5 - min(h - sun.rise, sun.set - h) / 1.5 if k < 0 then return 0 elseif k > 1 then return 1 end return k end local MINER_X, MINER_Y, MINER_W, MINER_H = 5, GROUND_Y - 8, 11, 8 local MINER = {} do local MAN = { ".+++.", "+++++", ".sss.", "#####", "#####", ".#.#.", "#...#" } local SUIT, HELMET, SKIN = char(58, 92, 180), char(255, 190, 50), char(232, 196, 156) local TOOL = char(170, 178, 194) local CHIP = char(mix(170, 178, 194, 255, 255, 255, 0.55)) local HANDLE = { { 5, 1, 7, -1 }, { 5, 2, 7, 2 }, { 5, 3, 7, 5 } } local CHIPS = { { 1, -3 }, { 2, -1 }, { 3, -4 } } local function tdiv(a, b) local q = a // b; if q < 0 and q * b ~= a then q = q + 1 end; return q end for ph = 0, 2 do local g = {} for y = 0, MINER_H - 1 do g[y] = {}; for x = 0, MINER_W - 1 do g[y][x] = char(0, 0, 0) end end local function set(x, y, c) x = x - MINER_X; y = y - MINER_Y; if g[y] and x >= 0 and x < MINER_W then g[y][x] = c end end local mx, my = 5, GROUND_Y - 7 for r = 1, 7 do for c = 1, 5 do local ch = MAN[r]:sub(c, c) if ch == "#" then set(mx + c - 1, my + r - 1, SUIT) elseif ch == "+" then set(mx + c - 1, my + r - 1, HELMET) elseif ch == "s" then set(mx + c - 1, my + r - 1, SKIN) end end end local hd = HANDLE[ph + 1] local hx, hy, tx, ty = mx + hd[1], my + hd[2], mx + hd[3], my + hd[4] local steps = math.max(math.abs(tx - hx), math.abs(ty - hy)) if steps < 1 then steps = 1 end for i = 0, steps do set(hx + tdiv((tx - hx) * i, steps), hy + tdiv((ty - hy) * i, steps), TOOL) end set(tx, ty, TOOL); set(tx + 1, ty, TOOL) set(tx, ty + (ph == 2 and -1 or 1), TOOL) if ph == 2 then for _, c in ipairs(CHIPS) do set(tx + c[1], ty + c[2], CHIP) end end local rows = {} for y = 0, MINER_H - 1 do rows[y + 1] = concat(g[y], "", 0, MINER_W - 1) end MINER[ph] = concat(rows) end end local SEQ = { 0, 0, 1, 2, 2, 1 } local function age_color(s) if s <= 600 then return OK_C[1], OK_C[2], OK_C[3] end local f = (s - 600) / 1200.0 if f < 0 then f = 0 elseif f > 1 then f = 1 end if f < 0.5 then return mix(OK_C[1], OK_C[2], OK_C[3], MID_C[1], MID_C[2], MID_C[3], f * 2.0) else return mix(MID_C[1], MID_C[2], MID_C[3], LATE_C[1], LATE_C[2], LATE_C[3], (f - 0.5) * 2.0) end end local CH_BG = { 26, 36, 92 } local CH_Y, CH_SZ, CH_PITCH, GHOST_X = 7, 10, 14, 52 local CH_LINK = { 150, 160, 185 } local ch_blocks local CH_PERIM = {} for i = 0, 9 do CH_PERIM[#CH_PERIM + 1] = { i, 0 } end for i = 1, 9 do CH_PERIM[#CH_PERIM + 1] = { 9, i } end for i = 8, 0, -1 do CH_PERIM[#CH_PERIM + 1] = { i, 9 } end for i = 8, 1, -1 do CH_PERIM[#CH_PERIM + 1] = { 0, i } end local function build_chain() ch_blocks = {} for i, k in ipairs({ 1.0, 0.8, 0.64, 0.52 }) do local edge = char(floor(190 * k), floor(100 * k), floor(10 * k)) local fill = char(floor(247 * k), floor(147 * k), floor(26 * k)) local line = char(floor(255 * k), floor(214 * k), floor(150 * k)) local rows = {} for y = 0, CH_SZ - 1 do local row = {} for x = 0, CH_SZ - 1 do if x == 0 or y == 0 or x == CH_SZ - 1 or y == CH_SZ - 1 then row[x + 1] = edge elseif (y == 3 or y == 5 or y == 7) and x >= 2 and x <= 7 then row[x + 1] = line else row[x + 1] = fill end end rows[y + 1] = concat(row) end ch_blocks[i] = concat(rows) end end local function draw_chain(t, e, p) rect(0, 0, W, H, CH_BG[1], CH_BG[2], CH_BG[3]) local off, flash = 0, 0 if p then off = floor(CH_PITCH * (1 - p) ^ 3 + 0.5) flash = 1 - p / 0.4 end for i = 0, 4 do local x = GHOST_X - CH_PITCH * (i + 1) + off if x + CH_PITCH > 0 then if i == 0 then px(x + CH_SZ, CH_Y + 4, CH_LINK[1], CH_LINK[2], CH_LINK[3]); px(x + CH_SZ, CH_Y + 5, CH_LINK[1], CH_LINK[2], CH_LINK[3]) px(x + CH_SZ + 2, CH_Y + 4, CH_LINK[1], CH_LINK[2], CH_LINK[3]); px(x + CH_SZ + 2, CH_Y + 5, CH_LINK[1], CH_LINK[2], CH_LINK[3]) else rect(x + CH_SZ, CH_Y + 4, CH_PITCH - CH_SZ, 2, CH_LINK[1], CH_LINK[2], CH_LINK[3]) end blit_rgb(ch_blocks[min(i + 1, 4)], x, CH_Y, CH_SZ, CH_SZ) if i == 0 and flash > 0 then blend_rect(x, CH_Y, CH_SZ, CH_SZ, 255, 255, 255, 0.8 * flash) end end end local r, g, b = 150, 160, 190 if e then r, g, b = age_color(e) end local gx, n = GHOST_X + off, floor(t * 8) for i, q in ipairs(CH_PERIM) do if (i + n) % 4 < 2 then px(gx + q[1], CH_Y + q[2], r, g, b) end end local m = floor(t * 12) for j = 0, 2 do local h = umod(hash32(m * 0x9E3779B1 + j * 0x85EBCA6B), 36) blend(gx + 2 + h % 6, CH_Y + 2 + h // 6, r, g, b, 0.7) end return 200, 210, 235 end local FM_WALL, FM_FLOOR = { 64, 72, 92 }, { 46, 52, 66 } local FM_Y, FM_W, FM_H, FM_GAP, FM_N = 6, 14, 9, 2, 4 local FM_X = (W - (FM_N * FM_W + (FM_N - 1) * FM_GAP)) // 2 local fm_bg, fm_fan local COIN = { ".###.", "#####", "##o##", "#####", ".###." } local function draw_coin(x, y, p) local cy, a = y - floor(p * 8), p < 0.6 and 1 or (1 - p) / 0.4 for r = 1, 5 do for c = 1, 5 do local ch = COIN[r]:sub(c, c) if ch == "#" then blend(x + c - 1, cy + r - 1, 255, 200, 60, a) elseif ch == "o" then blend(x + c - 1, cy + r - 1, 200, 140, 20, a) end end end end local function build_farm() local wall = char(FM_WALL[1], FM_WALL[2], FM_WALL[3]) local body, edge, vent = char(176, 182, 194), char(96, 102, 116), char(110, 116, 130) local rows = {} for y = 0, SCENE_H - 1 do local row = {} for x = 0, W - 1 do local c = wall if y == 15 then c = char(150, 156, 170) elseif y == 16 then c = char(100, 106, 120) elseif y == 17 then c = char(44, 48, 60) else local lx, ly = (x - FM_X) % (FM_W + FM_GAP), y - FM_Y if x >= FM_X and (x - FM_X) // (FM_W + FM_GAP) < FM_N and lx < FM_W and ly >= 0 and ly < FM_H then local ex, ey = lx == 0 or lx == FM_W - 1, ly == 0 or ly == FM_H - 1 if ex and ey then c = wall elseif ex or ey then c = edge elseif lx >= 9 and lx <= 12 and (ly == 5 or ly == 7) then c = vent else c = body end end end row[x + 1] = c end rows[y + 1] = concat(row) end fm_bg = concat(rows) fm_fan = {} for f = 0, 7 do local g = {} for y = 0, 6 do g[y] = {} for x = 0, 6 do local dx, dy = x - 3, y - 3 g[y][x] = (dx * dx + dy * dy <= 11) and char(34, 38, 48) or body end end for k = 0, 2 do local a = f * (2.0943951 / 8) + k * 2.0943951 for r = 1, 3 do local x, y = 3 + lround(cos(a) * r), 3 + lround(sin(a) * r) g[y][x] = char(140, 148, 162) end end g[3][3] = char(210, 214, 222) local rr = {} for y = 0, 6 do rr[y + 1] = concat(g[y], "", 0, 6) end fm_fan[f] = concat(rr) end end local function draw_farm(t, e, p, height) blit_rgb(fm_bg, 0, 0, W, SCENE_H) rect(0, SCENE_H, W, H - SCENE_H, FM_FLOOR[1], FM_FLOOR[2], FM_FLOOR[3]) local fan = fm_fan[floor(t * 16) % 8] local busy = 0.35 + 0.45 * min(1, (e or 0) / 1800) local tick = floor(t * 10) for i = 0, FM_N - 1 do local x0 = FM_X + i * (FM_W + FM_GAP) blit_rgb(fan, x0 + 1, FM_Y + 1, 7, 7) if p then px(x0 + 10, FM_Y + 2, 255, 190, 40); px(x0 + 12, FM_Y + 2, 255, 190, 40) else px(x0 + 10, FM_Y + 2, 60, 200, 90) if umod(hash32(i * 0x9E3779B1 + tick * 0x85EBCA6B), 100) < busy * 100 then px(x0 + 12, FM_Y + 2, 140, 255, 150) else px(x0 + 12, FM_Y + 2, 40, 60, 48) end end end if p and height then draw_coin(FM_X + umod(height, FM_N) * (FM_W + FM_GAP) + 5, FM_Y - 4, p) end return 200, 210, 230 end local function win_at(len) local t = data.time return t.unix // len, t.unix % len + t.ms / 1000 end local DRONE = { "a.a.a", ".bbb.", "..l..", "..c.." } local DRONE_C = { a = { 200, 205, 215 }, b = { 70, 74, 90 }, l = { 130, 130, 140 }, c = { 255, 200, 60 } } local function draw_guest(t, k) local win, fw = win_at(60) local h = hash32(win * 0x9E3779B1 + 91) local right = umod(h >> 8, 2) == 0 if k < 0.5 then if umod(h, 3) == 0 then return end local v = 9 local dur = (W + 10) / v local e = fw - umod(h >> 4, math.max(1, floor(60 - dur))) if e < 0 or e > dur then return end local x = floor(right and -5 + e * v or W + 5 - e * v) local y = 6 + floor(sin(t * 2.2) + 0.5) local spin = floor(t * 15) % 2 for r = 1, 4 do for c = 1, 5 do local ch = DRONE[r]:sub(c, c) if ch == "a" and (c + spin) % 2 == 0 then ch = "." end local col = DRONE_C[ch] if col then px(x + c - 1, y + r - 1, col[1], col[2], col[3]) end end end else if umod(h, 2) == 0 then return end local v = 2.5 local dur = (SUN_X - 30) / v local e = fw - umod(h >> 4, math.max(1, floor(60 - dur))) if e < 0 or e > dur then return end local x = SUN_X - 1 - e * v local a = min(1, e / 1.5, (x - 29) / 6) blend(floor(x), 1 + umod(h >> 12, 4) + floor(e * 0.25), 255, 255, 255, 0.95 * a) end end local function draw_land(t, p) local stage = floor(night_k() * 5 + 0.5) if stage ~= land_stage then build_land(stage) end local k = land_k blit_rgb(land_bg, 0, 0, W, SCENE_H) local gc = LAND.ground_now rect(0, SCENE_H, W, H - SCENE_H, gc[1], gc[2], gc[3]) if k < 0.5 then blit_rgb(land_disc, SUN_X, SUN_Y, SUN_W, SUN_H, 0, 0, 0, 0.92 + 0.08 * sin(fmod(t * 3.0, 6.28318))) else blit_rgb(land_disc, SUN_X, SUN_Y, SUN_W, SUN_H, 0, 0, 0) local a = (k - 0.5) * 2 for i, st in ipairs(land_stars) do blend(st[1], st[2], 255, 250, 220, a * (0.55 + 0.45 * sin(t * 2.1 + i * 1.7))) end end draw_guest(t, k) blit_rgb(MINER[SEQ[floor(t * 6) % 6 + 1]], MINER_X, MINER_Y, MINER_W, MINER_H, 0, 0, 0) if p then draw_coin(11, GROUND_Y - 9, p) end if k >= 0.5 then blend(10, 9, 255, 240, 170, 0.9) blend(11, 10, 255, 230, 150, 0.45) blend(12, 11, 255, 230, 150, 0.25) return 215, 225, 245 end return HGT_R, HGT_G, HGT_B end function on_settings() net.fetch("hash", "/api/blocks/tip/hash", 60) land_stage = nil if cfg.scene == "chain" then build_chain() elseif cfg.scene == "farm" then build_farm() end end local function split_words(s) local n, best, best_max = #s, nil, 9999 for i = 2, n - 1 do if sub(s, i, i) == " " then local l, r = i - 1, n - i local m = l > r and l or r if m < best_max then best_max = m; best = i end end end if not best then return nil end return sub(s, 1, best - 1), sub(s, best + 1) end local function chars(s) return utf8.len(s) or #s end local function cut_chars(s, n) local i = utf8.offset(s, n + 1) return i and sub(s, 1, i - 1) or s end local function char_at(s, n) local i = utf8.offset(s, n) if not i then return "" end local j = utf8.offset(s, n + 1) return sub(s, i, j and j - 1 or #s) end local function truncate_to_fit(s, max_w, adv) local max_chars = (max_w + 1) // adv if chars(s) <= max_chars then return s end local keep = max_chars - 2 while keep > 0 and char_at(s, keep) == " " do keep = keep - 1 end if keep <= 0 then return cut_chars(s, max_chars) end return cut_chars(s, keep) .. ".." end local function draw_pool(raw) local s = upper(cut_chars(raw, 31)) if s == "" then return end if text_width(s) <= POOL_MAXW then text_center(POOL_1, s, POOL_R, POOL_G, POOL_B) return end local a, b = split_words(s) if a and text_width(a) <= POOL_MAXW and text_width(b) <= POOL_MAXW then text_center(POOL_2A, a, POOL_R, POOL_G, POOL_B) text_center(POOL_2B, b, POOL_R, POOL_G, POOL_B) return end if text_width(s, F_SMALL) <= POOL_MAXW then text_center(POOL_SM, s, POOL_R, POOL_G, POOL_B, F_SMALL) return end if a and text_width(a, F_SMALL) <= POOL_MAXW and text_width(b, F_SMALL) <= POOL_MAXW then text_center(POOL_2A + 1, a, POOL_R, POOL_G, POOL_B, F_SMALL) text_center(POOL_2B + 1, b, POOL_R, POOL_G, POOL_B, F_SMALL) return end text_center(POOL_SM, truncate_to_fit(s, POOL_MAXW, ADV5), POOL_R, POOL_G, POOL_B, F_SMALL) end local FUTURE_TOL = 7200 local warned = nil local last_block = nil local seen_ts, seen_unix = nil, nil local function elapsed(b) local t = data.time if not (t and t.ok and t.unix and b.timestamp) then return nil end local e = t.unix - b.timestamp if e >= 86400 * 7 or e < -FUTURE_TOL then if warned ~= b.timestamp then warned = b.timestamp print(fmt("lastblock: no age - now=%d block=%d diff=%d", t.unix, b.timestamp, e)) end return nil end if seen_ts ~= b.timestamp then seen_ts, seen_unix = b.timestamp, t.unix end if seen_unix < b.timestamp then e = t.unix - seen_unix end if e < 0 then e = 0 end return e end local HALVING = 210000 local FW_N, FW_T, FW_UP, FW_BURST = 4, 2.0, 0.6, 1.2 local FW_V, FW_G, FW_RAYS = 11, 8, 16 local FW_PAL = { { 255, 80, 80 }, { 140, 255, 150 }, { 150, 235, 255 }, { 255, 214, 80 }, { 255, 120, 240 }, { 247, 147, 26 } } local FW_DIR = {} for k = 0, FW_RAYS - 1 do FW_DIR[k + 1] = { cos(k * 6.28318 / FW_RAYS), sin(k * 6.28318 / FW_RAYS) } end local function draw_fireworks(t) clip(0, 0, W, SCENE_H) for i = 0, FW_N - 1 do local tt = t + i * FW_T / FW_N local c, tau = floor(tt / FW_T), fmod(tt, FW_T) local key = c * 7 + i * 131 local x0, yb = 8 + umod(hash32(key + 1), W - 16), 3 + umod(hash32(key + 2), 6) local col = FW_PAL[umod(hash32(key + 3), #FW_PAL) + 1] if tau < FW_UP then local q = 1 - tau / FW_UP local y = floor(yb + (SCENE_H - yb) * q * q) blend(x0, y, 255, 240, 200, 1) blend(x0, y + 1, 255, 180, 90, 0.5) elseif tau < FW_UP + FW_BURST then local s = tau - FW_UP local a = min(1, 2 * (1 - s / FW_BURST)) for _, d in ipairs(FW_DIR) do for j = 0, 2 do local sj = s - j * 0.07 if sj > 0 then blend(floor(x0 + d[1] * FW_V * sj + 0.5), floor(yb + d[2] * FW_V * sj + FW_G * sj * sj + 0.5), col[1], col[2], col[3], a * (1 - j * 0.35)) end end end if s < 0.12 then blend(x0, yb, 255, 255, 255, 1) end end end clip() end local seen_h, new_at = nil, nil local NEW_S = 1.5 local F_GATE = { font = "4x6" } local function gate(s, y, r, g, b) if s.ok then return true end r, g, b = r or 255, g or 250, b or 232 text_center(y, data.net.mode ~= "online" and txt.offline or not data.net.up and txt.nowifi or s.code ~= 0 and "ERR " .. s.code or txt.loading, r, g, b) if s.code ~= 0 then text_center(y + 10, txt.console, r, g, b, F_GATE) end return false end local hash_raw, block_path function render() local t = frame / FPS if web.hash ~= hash_raw then hash_raw = web.hash local h = hash_raw and hash_raw:match("^%x+") block_path = h and #h == 64 and "/api/v1/block/" .. h or nil end if block_path then net.fetch("block", block_path) end if web.block then last_block = web.block end local b = last_block local e = b and elapsed(b) if b and b.height and b.height ~= seen_h then if seen_h then new_at = t end seen_h = b.height end if new_at and (t < new_at or t - new_at >= NEW_S) then new_at = nil end local p = new_at and (t - new_at) / NEW_S local nr, ng, nb if cfg.scene == "chain" then nr, ng, nb = draw_chain(t, e, p) elseif cfg.scene == "farm" then nr, ng, nb = draw_farm(t, e, p, seen_h) else nr, ng, nb = draw_land(t, p) end if b and b.height and b.height % HALVING == 0 then draw_fireworks(t) end local br, bg_, bb = CARD_BRD[1], CARD_BRD[2], CARD_BRD[3] if e then if e > BLINK_S and (frame // (FPS * 2 // 5)) % 2 == 1 then br, bg_, bb = CARD_BRD[1], CARD_BRD[2], CARD_BRD[3] else br, bg_, bb = age_color(e) end end round_rect(CARD_X, CARD_Y, CARD_W, CARD_H, CARD_BG[1], CARD_BG[2], CARD_BG[3], br, bg_, bb, 3) if b and b.height and b.height > 0 then text(2, 1, fmt("%d", b.height), nr, ng, nb, F_SMALL) end text_center(TITLE_Y, txt.title, TIT_R, TIT_G, TIT_B, F_SMALL) rect(CARD_X + 4, TITLE_Y + 6, CARD_W - 8, 1, DIV_R, DIV_G, DIV_B) if not gate(data.src.hash, 32, ACC_R, ACC_G, ACC_B) then return end if not b then gate(data.src.block, 32, ACC_R, ACC_G, ACC_B) return end local clock = e and fmt("%02d:%02d", e // 60, e % 60) or "--:--" if text_width(clock, F_BIG) <= CARD_W - 6 then text_center(CLOCK_Y, clock, ACC_R, ACC_G, ACC_B, F_BIG_CELL) else text_center(CLOCK_Y + 2, clock, ACC_R, ACC_G, ACC_B, CELL) end local pool = b.extras and b.extras.pool and b.extras.pool.name draw_pool(pool or "?") end