0xa85e2099…e34asent to0xd28694b1…4215·#25,412,202·view on Etherscan
let value = 0;
let shift = 0;
let remaining = bits;
while (remaining > 0) {
const current = this.bytes[this.byteIndex] || 0;
const available = 8 - this.bitIndex;
const take = Math.min(available, remaining);
const mask = (1 << take) - 1;
value |= ((current >> this.bitIndex) & mask) << shift;
this.bitIndex += take;
if (this.bitIndex === 8) {
this.bitIndex = 0;
this.byteIndex += 1;
}
shift += take;
remaining -= take;
}
return value;
}
}
function grFrameLines(values, columns, rows) {
const lines = [];
for (let row = 0; row < rows; row += 1) {
lines.push(values.slice(row * columns, row * columns + columns).join(""));
}
return lines.join("\n");
}
function grDecodeToneFrames(encoded, columns, rows, frameCount) {
const reader = new GrBitReader(grBase64Bytes(encoded));
const tones = ["0", "2", "4", "6", "9", "B", "D", "F"];
const frames = [];
const cells = columns * rows;
for (let frame = 0; frame < frameCount; frame += 1) {
const values = new Array(cells);
for (let cell = 0; cell < cells; cell += 1) values[cell] = tones[reader.read(3)] || "0";
frames.push(grFrameLines(values, columns, rows));
}
return frames;
}
function grDecodeStyleFrames(encoded, columns, rows, frameCount, indexBits, valueBits, storageMode) {
if (storageMode === "dense4bit") return grDecodeDense4BitStyleFrames(encoded, columns, rows, frameCount);
return grDecodeSparseStyleFrames(encoded, columns, rows, frameCount, indexBits, valueBits);
}
function grDecodeDense4BitStyleFrames(encoded, columns, rows, frameCount) {
const reader = new GrBitReader(grBase64Bytes(encoded));
const frames = [];
const cells = columns * rows;
for (let frame = 0; frame < frameCount; frame += 1) {
const values = new Array(cells);
for (let cell = 0; cell < cells; cell += 1) values[cell] = reader.read(4).toString(16).toUpperCase();
frames.push(grFrameLines(values, columns, rows));
}
return frames;
}
function grDecodeSparseStyleFrames(encoded, columns, rows, frameCount, indexBits, valueBits) {
const reader = new GrBitReader(grBase64Bytes(encoded));
const frames = [];
const cells = columns * rows;
for (let frame = 0; frame < frameCount; frame += 1) {
const values = new Array(cells).fill("0");
const count = reader.read(16);
for (let item = 0; item < count; item += 1) {
const index = reader.read(indexBits);
const style = reader.read(valueBits);
if (index < cells) values[index] = String(style);
}
frames.push(grFrameLines(values, columns, rows));
}
return frames;
}
const grConfig = grDecodeJson(GR_CONFIG_B64);
const grRuntimeSeed = String(grConfig?.ritualEngineCompatibility?.seedField?.value || grConfig?.seed || "");
const grRuntime = GENESIS_RUNTIME_BY_SEED[grRuntimeSeed] || GENESIS_RUNTIME_BY_SEED[Object.keys(GENESIS_RUNTIME_BY_SEED)[0]];
Object.assign(SIGNAL_RITUAL_ENGINE, {
glyphs: grRuntime.glyphs || grConfig.configuredGlyphs || "",
ritualGlyphs: grRuntime.ritualGlyphs || (grConfig.configuredGlyphs || "").replace(/\s/g, ""),
displayedFrames: grConfig.displayedFrames || grRuntime.displayedFrames,
playbackMode: grConfig.playbackMode || grRuntime.playbackMode || "normal",
timelineFrames: grConfig.timelineFrames || grRuntime.timelineFrames || grRuntime.displayedFrames,
fps: grRuntime.fps || 12,
keyframeSourceFrames: grRuntime.keyframeSourceFrames,
storageSourceFrames: grRuntime.storageSourceFrames,
interpolation: grRuntime.interpolation || "none",
seed: grRuntime.seed,
procedural: Boolean(grConfig.procedural ?? grRuntime.procedural),
proceduralOverlay: Boolean(grConfig.proceduralOverlay ?? grRuntime.proceduralOverlay),
proceduralMotion: grConfig.proceduralMotion || grRuntime.proceduralMotion || { enabled: false },
visualRenderer: grRuntime.visualRenderer,
});
const keyframeSourceFrames = SIGNAL_RITUAL_ENGINE.storageSourceFrames || SIGNAL_RITUAL_ENGINE.keyframeSourceFrames;
const columns = Math.max(1, Number(grConfig.grid?.columns) || grRuntime.columns || 1);
const rows = Math.max(1, Number(grConfig.grid?.rows) || grRuntime.rows || 1);
const cell = Math.max(1, Number(grRuntime.cell) || 16);
const svgNs = "http://www.w3.org/2000/svg";
const art = document.getElementById("art");
const artifactFrameLayer = document.getElementById("artifactFrame");
const glowCellsLayer = document.getElementById("glowCells");
const cellsLayer = document.getElementById("cells");
const scanlinesLayer = document.getElementById("scanlines");
const staticLayer = document.getElementById("static");
const vignetteLayer = document.getElementById("vignette");
const artifactFrame = grRuntime.artifactFrame || null;
const artifactFramePad = artifactFrame?.padding || { left: 0, right: 0, top: 0, bottom: 0 };
const artifactFrameColumns = artifactFrame ? columns + (artifactFramePad.left || 0) + (artifactFramePad.right || 0) : columns;
const artifactFrameRows = artifactFrame ? rows + (artifactFramePad.top || 0) + (artifactFramePad.bottom || 0) : rows;
const artworkOffsetX = (artifactFramePad.left || 0) * cell;
const artworkOffsetY = (artifactFramePad.top || 0) * cell;
const outerMargin = 3;
const cells = [];
const rowOffsets = new Array(rows).fill(0);
const scanlineRects = [];
const staticRects = [];
const toneLineCache = [];
const styleLineCache = [];
const toneFillCache = Object.create(null);
const toneValueMap = { "0": 0, "2": 2 / 15, "4": 4 / 15, "6": 6 / 15, "9": 9 / 15, "B": 11 / 15, "D": 13 / 15, "F": 1 };
const SMOOTH_MARKETPLACE_MODE = true;
const storedToneFrames = grDecodeToneFrames(GR_TONE_B64, columns, rows, keyframeSourceFrames.length);
const storedStyleFrames = grDecodeStyleFrames(GR_STYLE_B64, columns, rows, keyframeSourceFrames.length, grConfig.styleIndexBits || 13, grConfig.styleValueBits || 3, grConfig.styleStorageMode || "sparseAnchors");
const RENDER_GLOW_ENABLED = Number(SIGNAL_RITUAL_ENGINE.visualRenderer?.effects?.asciiGlow || 0) > 0;
const CACHE_FRAME_GROUPS = !(SIGNAL_RITUAL_ENGINE.proceduralMotion && SIGNAL_RITUAL_ENGINE.proceduralMotion.enabled);
const PROCEDURAL_MOTION_CLOCK_FPS = 60;
const PROCEDURAL_RENDER_FPS = 60;
const PROCEDURAL_REPAINT_FPS = 60;
const frameGroups = [];
const warmingFrames = new Set();
let activeFrameGroup = null;
let lastProceduralPaintFrame = -Infinity;
setupSvgViewport();
let tick = -1;
if (!CACHE_FRAME_GROUPS) {
createCellNodes(cellsLayer, cells);
}
function setupSvgViewport() {
if (!art) return;
const width = artifactFrameColumns * cell;
const height = artifactFrameRows * cell;
const aspect = artifactFrameColumns / Math.max(1, artifactFrameRows);
art.setAttribute("viewBox", (-outerMargin) + " " + (-outerMargin) + " " + (width + outerMargin * 2) + " " + (height + outerMargin * 2));
art.setAttribute("preserveAspectRatio", "xMidYMid meet");
art.style.width = "auto";
art.style.height = "min(100vh, calc(100vw / " + aspect + "), " + height + "px)";
const transform = artworkOffsetX || artworkOffsetY ? "translate(" + artworkOffsetX + " " + artworkOffsetY + ")" : "";
if (transform) {
glowCellsLayer.setAttribute("transform", transform);
cellsLayer.setAttribute("transform", transform);
scanlinesLayer.setAttribute("transform", transform);
staticLayer.setAttribute("transform", transform);
vignetteLayer.setAttribute("transform", transform);
}
svgDrawArtifactFrame();
}
function svgDrawArtifactFrame() {
if (!artifactFrame || !artifactFrameLayer) return;
artifactFrameLayer.textContent = "";
const color = SIGNAL_RITUAL_ENGINE.visualRenderer.background === "#f7f7f2" ? "#08090b" : "#f3f0e8";
const corner = artifactFrame.borderGlyphs?.corner || "+";
const horizontal = artifactFrame.borderGlyphs?.horizontal || "-";
const vertical = artifactFrame.borderGlyphs?.vertical || "|";
function addText(text, column, row) {
const node = document.createElementNS(svgNs, "text");
node.setAttribute("class", "cell");
node.setAttribute("x", column * cell + cell / 2);
node.setAttribute("y", row * cell + cell / 2);
node.setAttribute("font-size", Math.round(cell * 1.18));
node.setAttribute("font-weight", "700");
node.setAttribute("fill", color);
node.setAttribute("opacity", "0.92");
node.textContent = text;
artifactFrameLayer.appendChild(node);
}
svgDrawBorderLine(0, color, corner, horizontal, [
{ text: artifactFrame.collectionName || "Signal Rituals", align: "left", max: Math.floor(artifactFrameColumns * 0.38) },
{ text: artifactFrame.artworkName || "Untitled", align: "right", max: Math.floor(artifactFrameColumns * 0.48) },
]);
svgDrawBorderLine(artifactFrameRows - 1, color, corner, horizontal, [
{ text: "Seed: " + (artifactFrame.seed || "-"), align: "right", max: Math.floor(artifactFrameColumns * 0.44) },
]);
for (let row = 1; row < artifactFrameRows - 1; row += 1) {
addText(vertical, 0, row);
addText(vertical, artifactFrameColumns - 1, row);
}
}
function svgFrameText(text, maxLength) {
text = String(text || "").replace(/[^\x20-\x7E]/g, "").replace(/\s+/g, " ").trim();
if (text.length <= maxLength) return text;
return maxLength <= 3 ? text.slice(0, maxLength) : text.slice(0, maxLength - 3) + "...";
}
function svgDrawBorderLine(row, color, corner, horizontal, segments = []) {
const line = new Array(artifactFrameColumns).fill(horizontal);
for (let column = 0; column < artifactFrameColumns; column += 1) {
if (column === 0 || column === artifactFrameColumns - 1) line[column] = corner;
}
const occupied = new Array(artifactFrameColumns).fill(false);
occupied[0] = true;
occupied[artifactFrameColumns - 1] = true;
for (const segment of segments) {
const text = " " + svgFrameText(segment.text, Math.max(0, segment.max || artifactFrameColumns - 4)) + " ";
let start = 2;
if (segment.align === "center") start = Math.floor((artifactFrameColumns - text.length) / 2);
if (segment.align === "right") start = artifactFrameColumns - text.length - 2;
start = Math.max(1, Math.min(artifactFrameColumns - text.length - 1, start));
for (let index = 0; index < text.length; index += 1) {
const column = start + index;
if (column <= 0 || column >= artifactFrameColumns - 1 || occupied[column]) continue;
line[column] = text[index];
occupied[column] = true;
}
}
for (let column = 0; column < artifactFrameColumns; column += 1) {
const node = document.createElementNS(svgNs, "text");
node.setAttribute("class", "cell");
node.setAttribute("x", column * cell + cell / 2);
node.setAttribute("y", row * cell + cell / 2);
node.setAttribute("font-size", Math.round(cell * 1.18));
node.setAttribute("font-weight", "700");
node.setAttribute("fill", color);
node.setAttribute("opacity", "0.92");
node.textContent = line[column];
artifactFrameLayer.appendChild(node);
}
}
function createCellNodes(parent, output) {
for (let row = 0; row < rows; row += 1) {
for (let column = 0; column < columns; column += 1) {
output.push(svgCreateCellNode(parent, column, row));
}
}
}
function svgCreateCellNode(parent, column, row) {
const tuning = SIGNAL_RITUAL_ENGINE.visualRenderer.rendererTuning || {};
const glyphScale = tuning.glyphScale ?? 1.25;
const text = document.createElementNS(svgNs, "text");
text.setAttribute("class", "cell");
text.setAttribute("x", column * cell + cell / 2);
text.setAttribute("y", row * cell + cell / 2);
text.setAttribute("font-size", Math.round(cell * glyphScale));
text.textContent = " ";
parent.appendChild(text);
return text;
}
function svgRowGlitchOffset(row, frame) {
const effects = grEffectSettings();
const passes = grActiveGlitchPasses(frame);
const fullWidth = columns * cell;
const rowY = row * cell;
let offset = 0;
for (const pass of passes) {
const seed = frame * 4099 + pass.index * 10007 + 101;
const time = frame * (0.016 + pass.speed * 0.3);
if (p