0x019b0ee2…4681sent to0x9c771720…3bd2·#24,812,249·view on Etherscan
(function () {
const DATA = window.T256 || {};
const PROJECT_INFO = {
description: [
"TERMINAL256 explores the shift from static images to systems.",
"256 fully on-chain terminals each carrying a signal.",
"The artwork is not fixed. It is continuously resolved through interaction."
],
homepage: "https://terminal256.xyz",
creator: "filter8",
x: "https://x.com/0xfilter8"
};
const cover = document.getElementById("cover");
const coverArt = document.getElementById("coverArt");
const miniArt = document.getElementById("miniArt");
const terminal = document.getElementById("terminal");
const historyEl = document.getElementById("history");
const inputEl = document.getElementById("cmdinput");
const phaseLine = document.getElementById("phaseLine");
const actionsEl = document.getElementById("actions");
let isOpen = false;
let asciiRequestId = 0;
function safe(v, fallback) {
return v === undefined || v === null || v === "" ? fallback : v;
}
function num(v, fallback) {
const n = Number(v);
return Number.isFinite(n) ? n : fallback;
}
function clamp(v, min, max) {
return Math.max(min, Math.min(max, v));
}
function clearHistory() {
historyEl.innerHTML = "";
}
function scrollBottom() {
historyEl.scrollTop = historyEl.scrollHeight;
}
function appendParagraph(className, text) {
const p = document.createElement("p");
p.className = className;
p.textContent = text || "\u00A0";
historyEl.appendChild(p);
scrollBottom();
}
function line(text, tone) {
appendParagraph("t256-line" + (tone ? " " + tone : ""), text);
}
function htmlLine(html) {
const p = document.createElement("p");
p.className = "t256-linkrow";
p.innerHTML = html;
historyEl.appendChild(p);
scrollBottom();
}
function preBlock(text, className) {
const pre = document.createElement("pre");
pre.className = className;
pre.textContent = text;
historyEl.appendChild(pre);
scrollBottom();
}
function asciiBlock(text) {
preBlock(text, "t256-line t256-ascii");
}
function mapBlock(text) {
preBlock(text, "t256-line t256-map");
}
function commandLine(text) {
line("> " + text);
}
function artSrc() {
return (
DATA.imageData ||
DATA.image ||
DATA.imageUrl ||
DATA.imageURI ||
""
);
}
function makeArtNode(src) {
if (!src) return null;
if (typeof src === "string" && src.trim().startsWith("<svg")) {
const wrap = document.createElement("div");
wrap.innerHTML = src;
return wrap;
}
const img = document.createElement("img");
img.src = src;
img.alt = safe(DATA.collectionName, "TERMINAL256");
return img;
}
function mountArt(target) {
if (!target) return;
target.innerHTML = "";
const node = makeArtNode(artSrc());
if (node) target.appendChild(node);
}
function boot() {
clearHistory();
phaseLine.textContent = safe(DATA.phaseLabel, "TERMINAL ONLINE");
line("node: #" + safe(DATA.tokenId, "--"), "strong");
line("signal: " + safe(DATA.currentSignalName, "UNKNOWN"));
line("terminal online", "muted");
line("tap a command or type /info", "muted");
}
function normalizeCommand(value) {
const v = String(value || "").trim().toLowerCase();
if (!v) return "";
return v[0] === "/" ? v.slice(1) : v;
}
function padRight(str, width) {
const s = String(str);
return s.length >= width ? s : s + " ".repeat(width - s.length);
}
function padLeft(str, width) {
const s = String(str);
return s.length >= width ? s : " ".repeat(width - s.length) + s;
}
function encodeSignalCount(value) {
const n = Math.max(0, Math.round(num(value, 0)));
if (n <= 0) return "·";
const ones = n % 10;
const tens = Math.floor(n / 10) % 10;
const hundreds = Math.floor(n / 100) % 10;
const thousands = Math.floor(n / 1000);
return (
"█".repeat(thousands) +
"▓".repeat(hundreds) +
"▒".repeat(tens) +
"░".repeat(ones)
);
}
function deriveSignalPowerScore() {
if (DATA.signalPowerScore !== undefined && DATA.signalPowerScore !== null) {
return clamp(Math.round(num(DATA.signalPowerScore, 0)), 0, 100);
}
let score = 0;
score += num(DATA.affectedTargetsCount, num(DATA.affectedTargets, 0)) * 2;
score += num(DATA.executeCount, 0);
score += num(DATA.sendCount, 0);
score += num(DATA.syncCount, 0);
score += num(DATA.impulseCount, 0);
score += num(DATA.broadcastCount, 0) * 2;
score -= num(DATA.receivedEffectsCount, 0);
return clamp(Math.round(Math.max(0, score)), 0, 100);
}
function deriveExecuteCount() {
if (DATA.executeCount !== undefined && DATA.executeCount !== null) {
return Math.max(0, Math.round(num(DATA.executeCount, 0)));
}
if (DATA.stats && DATA.stats.executeCount !== undefined) {
return Math.max(0, Math.round(num(DATA.stats.executeCount, 0)));
}
return 0;
}
function deriveAffectedTargets() {
if (DATA.affectedTargetsCount !== undefined && DATA.affectedTargetsCount !== null) {
return Math.max(0, Math.round(num(DATA.affectedTargetsCount, 0)));
}
if (DATA.affectedTargets !== undefined && DATA.affectedTargets !== null) {
return Math.max(0, Math.round(num(DATA.affectedTargets, 0)));
}
if (DATA.stats && DATA.stats.affectedTargetsCount !== undefined) {
return Math.max(0, Math.round(num(DATA.stats.affectedTargetsCount, 0)));
}
return 0;
}
function deriveReceivedEffects() {
if (DATA.receivedEffectsCount !== undefined && DATA.receivedEffectsCount !== null) {
return Math.max(0, Math.round(num(DATA.receivedEffectsCount, 0)));
}
if (DATA.stats && DATA.stats.receivedEffectsCount !== undefined) {
return Math.max(0, Math.round(num(DATA.stats.receivedEffectsCount, 0)));
}
return 0;
}
function deriveManualActions() {
if (DATA.manualActionCount !== undefined && DATA.manualActionCount !== null) {
return Math.max(0, Math.round(num(DATA.manualActionCount, 0)));
}
if (DATA.stats && DATA.stats.manualActionCount !== undefined) {
return Math.max(0, Math.round(num(DATA.stats.manualActionCount, 0)));
}
return 0;
}
function deriveControllerActions() {
const direct = (DATA.controllerActionCount !== undefined && DATA.controllerActionCount !== null)
? Math.max(0, Math.round(num(DATA.controllerActionCount, 0)))
: 0;
const owner = (DATA.executorOwnerActionCount !== undefined && DATA.executorOwnerActionCount !== null)
? Math.max(0, Math.round(num(DATA.executorOwnerActionCount, 0)))
: 0;
if (DATA.stats) {
const directStats = DATA.stats.controllerActionCount !== undefined
? Math.max(0, Math.round(num(DATA.stats.controllerActionCount, 0)))
: direct;
const ownerStats = DATA.stats.executorOwnerActionCount !== undefined
? Math.max(0, Math.round(num(DATA.stats.executorOwnerActionCount, 0)))
: owner;
return directStats + ownerStats;
}
return direct + owner;
}
function deriveLockCount() {
if (DATA.lockCount !== undefined && DATA.lockCount !== null) {
return Math.max(0, Math.round(num(DATA.lockCount, 0)));
}
if (DATA.stats && DATA.stats.lockCount !== undefined) {
return Math.max(0, Math.round(num(DATA.stats.lockCount, 0)));
}
return 0;
}
function openExternal(url) {
try {
const win = window.open(url, "_blank", "noopener,noreferrer");
if (win) return;
} catch (err) {}
try {
window.location.href = url;
} catch (err) {}
}
function rotate(arr, n) {
const offset = ((n % arr.length) + arr.length) % arr.length;
return arr.slice(offset).concat(arr.slice(0, offset));
}
function signalGlyphSet() {
const family = String(safe(DATA.signalFamilyName, "")).toUpperCase();
const signal = String(safe(DATA.currentSignalName, "")).toUpperCase();
const power = String(safe(DATA.signalPowerName, "")).toUpperCase();
const bgBase = ["░", "▒", "▁", "▔", "▚", "▞"];
const fgBase = ["▓", "█", "▙", "▟", "▛", "▜"];
let familyOffset = 0;
if (family === "BROADCAST") familyOffset = 1;
else if (family === "SYNC") familyOffset = 2;
else if (family === "JAM") familyOffset = 3;
else if (family === "PORTAL") familyOffset = 4;
else if (family === "IMPULSE") familyOffset = 5;
let signalOffset = 0;
if (signal.includes("MINT")) signalOffset += 2;
if (signal.includes("VOID")) signalOffset += 4;
if (signal.includes("ECHO")) signalOffset += 1;
if (signal.includes("GATE")) signalOffset += 3;
let powerOffset = 0;
if (power === "LOW") powerOffset = 1;
else if (power === "MEDIUM") powerOffset = 2;
else if (power === "HIGH") powerOffset = 3;
else if (power === "STRONG") powerOffset = 4;
else if (power === "DOMINANT") powerOffset = 5;
const bgOffset = (familyOffset + signalOffset) % bgBase.length;
const fgOffset = (familyOffset + signalOffset + powerOffset) % fgBase.length;
return {
bg: rotate(bgBase, bgOffset),
fg: rotate(fgBase, fgOffset)
};
}
function cmdHelp() {
line("INFO SIGNAL MAP ASCII", "strong");
line("OPEN HELP CLEAR EXIT");
line("/info /signal /map /ascii");
line("/open /help /clear /exit");
}
function cmdInfo() {
line("INFO", "strong");
for (let i = 0; i < PROJECT_INFO.description.length; i++) {
line(PROJECT_INFO.description[i]);
}
line("creator: " + PROJECT_INFO.creator);
htmlLine(
'home: <a class="t256-openlink" href="' + PROJECT_INFO.homepage + '" target="_blank" rel="noopener noreferrer">terminal256.xyz</a>'
);
htmlLine(
'x: <a class="t256-openlink" href="' + PROJECT_INFO.x + '" target="_blank" rel="noopener noreferrer">x.com/0xfilter8</a>'
);
}
function cmdSignal() {
line("SIGNAL", "strong");
line("current: " + safe(DATA.currentSignalName, "UNKNOWN"));
line("family: " + safe(DATA.signalFamilyName, "UNKNOWN"));
line("power: " + safe(DATA.signalPowerName, "DORMANT"));
line("cooldown: " + safe(DATA.effectiveCooldown, 0) + "s");
}
function cmdOpen() {
line("OPEN", "strong");
line("Due to browser security, onchain functions below are not available in embedded (iframe) mode.", "muted");
htmlLine(
'Right click this link and open terminal in new tab (fullscreen): ' +
'<a class="t256-openlink" href="' + window.location.href + '" target="_blank" rel="noopener noreferrer">OPEN TERMINAL256</a>'
);
}
function cmdMap() {
const power = deriveSignalPowerScore();
const executions = deriveExecuteCount();
const affected = deriveAffectedTargets();
const received = deriveReceivedEffects();
const manual = deriveManualActions();
const control = deriveControllerActions();
const lock = deriveLockCount();
const rows = [
["POWER", power, encodeSignalCount(power)],
["EXECUTIONS", executions, encodeSignalCount(executions)],
["AFFECTED", affected, encodeSignalCount(affected)],
["RECEIVED", received, encodeSignalCount(received)],
["MANUAL", manual, encodeSignalCount(manual)],
["CONTROL", control, encodeSignalCount(control)],
["LOCK", lock, encodeSignalCount(lock)]
];
const labelWidth = 11;
const valueWidth = 4;
const output = rows.map(function (row) {
return (
padRight(row[0], labelWidth) +
" " +
padLeft(row[1], valueWidth) +
" " +
row[2]
);
}).join("\n");
line("MAP", "strong");
mapBlock(output);
}
function imageSourceForAscii() {
const src = artSrc();
if (!src) return null;
if (typeof src === "string" && src.trim().startsWith("<svg")) {
const blob = new Blob([src], { type: "image/svg+xml;charset=utf-8" });
return URL.createObjectURL(blob);
}
return src;
}
function loadImage(src) {
return new Promise(function (resolve, reject) {
const img = new Image();
img.decoding = "async";
img.onload = function () { resolve(img); };
img.onerror = function () { reject(new Error("Image failed to load")); };
img.src = src;
});
}
async function tokenImageToAscii() {
const src = imageSourceForAscii();
if (!src) return "ASCII UNAVAILABLE";
let objectUrlToRevoke = null;
if (typeof src === "string" && src.startsWith("blob:")) {
objectUrlToRevoke = src;
}
try {
const img = await loadImage(src);
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d", { willReadFrequently: true });
const width = 64;
const height = 64;
canvas.width = width;
canvas.height = height;
ctx.clearRect(0, 0, width, height);
ctx.drawImage(img, 0, 0, width, height);
const data = ctx.getImageData(0, 0, width, height).data;
const glyphs = signalGlyphSet();
const rows = [];
for (let y = 0; y < height; y++) {
let row = "";
for (let x = 0; x < width; x++) {
const i = (y * width + x) * 4;
const r = data[i];
const g = data[i + 1];
const b = data[i + 2];
const a = data[i + 3];
if (a < 10) {
row += " ";
continue;
}
const lum = (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255;
let char;
if (lum >= 0.6) {
const normalized = (lum - 0.6) / 0.4;
const idx = Math.max(
0,
Math.min(glyphs.fg.length - 1, Math.floor(normalized * glyphs.fg.length))
);
char = glyphs.fg[idx];
} else {
const normalized = lum / 0.6;
const idx = Math.max(
0,
Math.min(glyphs.bg.length - 1, Math.floor(normalized * glyphs.bg.length))
);
char = glyphs.bg[idx];
}
row += char + char;
}
rows.push(row);
}
return rows.join("\n");
} finally {
if (objectUrlToRevoke) {
try {
URL.revokeObjectURL(objectUrlToRevoke);
} catch (err) {}
}
}
}
async function cmdAscii() {
const requestId = ++asciiRequestId;
line("ASCII", "strong");
line("rendering token image...", "muted");
try {
const art = await tokenImageToAscii();
if (requestId !== asciiRequestId) return;
asciiBlock(art);
} catch (err) {
if (requestId !== asciiRequestId) return;
line("ascii render unavailable", "muted");
}
}
function focusInput() {
if (!inputEl) return;
try {
inputEl.focus();
inputEl.click();
inputEl.setSelectionRange(inputEl.value.length, inputEl.value.length);
} catch (err) {}
}
function openTerminal() {
if (isOpen) return;
isOpen = true;
cover.classList.add("is-hidden");
terminal.classList.add("is-open");
boot();
focusInput();
}
function closeTerminal() {
isOpen = false;
terminal.classList.remove("is-open");
cover.classList.remove("is-hidden");
}
async function run(raw, silentPrompt) {
const value = String(raw || "").trim();
if (!value) return;
if (!silentPrompt) {
commandLine(value);
}
const cmd = normalizeCommand(value);
if (cmd === "help") return cmdHelp();
if (cmd === "info") return cmdInfo();
if (cmd === "signal") return cmdSignal();
if (cmd === "map") return cmdMap();
if (cmd === "ascii") return cmdAscii();
if (cmd === "open") return cmdOpen();
if (cmd === "clear") {
clearHistory();
return;
}
if (cmd === "exit") {
closeTerminal();
return;
}
line("command not found", "muted");
line("try /help", "muted");
}
mountArt(coverArt);
mountArt(miniArt);
if (cover) {
cover.addEventListener("click", openTerminal);
cover.addEventListener("touchstart", openTerminal, { passive: true });
}
if (terminal) {
terminal.addEventListener("click", function (e) {
const tag = e.target && e.target.tagName ? e.target.tagName.toLowerCase() : "";
if (tag !== "button" && tag !== "a") {
focusInput();
}
});
}
if (actionsEl) {
actionsEl.addEventListener("click", function (e) {
const btn = e.target.closest("[data-cmd]");
if (!btn) return;
const cmd = btn.getAttribute("data-cmd");
if (!cmd) return;
run(cmd, true);
focusInput();
});
actionsEl.addEventListener("touchstart", function (e) {
const btn = e.target.closest("[data-cmd]");
if (!btn) return;
const cmd = btn.getAttribute("data-cmd");
if (!cmd) return;
e.preventDefault();
run(cmd, true);
focusInput();
}, { passive: false });
}
if (inputEl) {
inputEl.addEventListener("keydown", function (e) {
if (e.key === "Enter") {
e.preventDefault();
const v = inputEl.value.trim();
inputEl.value = "";
run(v || "/info");
}
});
}
document.addEventListener("keydown", function (e) {
if (!isOpen && (e.key === "Enter" || e.key === " ")) {
e.preventDefault();
openTerminal();
return;
}
if (!isOpen) return;
if (document.activeElement !== inputEl) {
if (e.key === "Enter") {
e.preventDefault();
run("/info", true);
focusInput();
return;
}
if (e.key.length === 1 || e.key === "/" || e.key === "Backspace") {
focusInput();
}
}
});
window.t256Run = run;
})();