0xa85e2099…e34asent to0xd28694b1…4215·#25,412,201·view on Etherscan
cluster * 211, time * 0.32) * 0.9);
if (grSmoothRandom(column * 1201 + cluster * 379 + 97, time) > chance) return 1;
const seed = column * 733 + cluster * 997 + Math.floor(time) * 433;
if (grSeeded(seed + 19) < 0.34) return Math.max(0.28, 1 - range * (0.22 + grSeeded(seed + 23) * 0.62));
return Math.min(3.25, 1 + range * (0.35 + grSeeded(seed + 29) * 1.65));
}
function grHighlightFill(tone) {
const effects = grEffectSettings();
const fill = (effects.asciiHighlightFill || 0) / 100;
if (fill <= 0) return 0;
const threshold = (effects.asciiHighlightThreshold || 100) / 100;
return grSmoothstep(threshold, 1, tone) * fill;
}
function grHighlightWeight(tone, style) {
if (style === "2" || style === "3") return 900;
if (style === "5") return 700;
const effects = grEffectSettings();
const tuning = SIGNAL_RITUAL_ENGINE.visualRenderer.rendererTuning || {};
const threshold = (effects.asciiHighlightThreshold || 100) / 100;
const fill = grHighlightFill(tone);
const strength = Math.max(fill, grSmoothstep(Math.max(0.48, threshold - 0.2), 1, tone) * (tuning.highlightWeightBoost ?? 0.9));
if (strength >= 0.48 || tone >= 0.78) return 900;
if (strength >= 0.18 || tone >= 0.58) return 800;
return 700;
}
function grShouldHighlightBlock(tone) {
const effects = grEffectSettings();
if (!effects.asciiHighlightBlocks) return false;
return tone >= (effects.asciiHighlightBlockThreshold || 100) / 100;
}
function grHighlightCellScale(tone, style, column, row, frame, recoveredAdaptiveDenseAnchor = false) {
const tuning = SIGNAL_RITUAL_ENGINE.visualRenderer.rendererTuning || {};
if (style === "2") return Math.min(3, Math.max(1.35, (grEffectSettings().asciiLargeScale || 2) * (tuning.largeAnchorScaleMultiplier ?? 0.95)));
if (recoveredAdaptiveDenseAnchor) return 1;
const fill = grHighlightFill(tone);
const threshold = (grEffectSettings().asciiHighlightThreshold || 100) / 100;
if (tone < Math.max(tuning.brightOpenToneFloor ?? 0.58, threshold - 0.16) && fill <= 0.02) return 1;
const base = 1 + Math.max(fill, grSmoothstep(Math.max(0.48, threshold - 0.18), 1, tone) * (tuning.brightScaleBoost ?? 0.72));
return Math.min(1.55, tuning.brightScaleMax ?? 2.45, base);
}
function grSkipBrightCrowding(tone, style, column, row, frame) {
if (style === "2" || style === "3") return false;
const tuning = SIGNAL_RITUAL_ENGINE.visualRenderer.rendererTuning || {};
const threshold = (grEffectSettings().asciiHighlightThreshold || 100) / 100;
const fill = grHighlightFill(tone);
if (tone < Math.max(tuning.brightCrowdToneFloor ?? 0.62, threshold - 0.12) && fill <= 0.06) return false;
const checker = (column + row + Math.floor(frame / 2)) % 2;
if (tone > 0.86) return column % 2 !== 0 || row % 2 !== 0;
return checker !== 0 && grSeeded(column * 997 + row * 449 + frame * 17) < (tuning.brightCrowdSkip ?? 0.7);
}
function grShouldUseDenseHighlightGlyph(tone, style) {
if (style === "1" || style === "2" || style === "3" || grIsEdgeStyle(style)) return false;
if (grIsDenseHighlightStyle(style)) return true;
const threshold = (grEffectSettings().asciiHighlightThreshold || 100) / 100;
return style === "4" || grHighlightFill(tone) > 0.02 || tone >= Math.max(0.66, threshold - 0.08);
}
const DENSE_HIGHLIGHT_GLYPHS = "$@&#";
function denseHighlightGlyphFromStyle(style) {
if (!style) return null;
const index = parseInt(style, 16) - 10;
return index >= 0 && index < DENSE_HIGHLIGHT_GLYPHS.length
? DENSE_HIGHLIGHT_GLYPHS[index]
: null;
}
function grDenseHighlightGlyph(tone, style, column, row, frame) {
const storedGlyph = denseHighlightGlyphFromStyle(style);
if (storedGlyph) return storedGlyph;
const glyphs = "$@&#";
const shaped = Math.max(0, Math.min(1, tone));
const base = Math.floor(shaped * glyphs.length);
const jitter = grSeeded(column * 811 + row * 353 + frame * 41);
const offset = jitter < 0.2 ? -1 : jitter > 0.82 ? 1 : 0;
const index = Math.max(0, Math.min(glyphs.length - 1, base + offset));
return glyphs[index] || "#";
}
function grGlyphFromTone(tone, column, row, frame) {
const chars = SIGNAL_RITUAL_ENGINE.glyphs;
if (!chars || !chars.length) return " ";
const shaped = Math.max(0, Math.min(1, tone));
let index = Math.round((1 - shaped) * (chars.length - 1));
const jitter = grSeeded(column * 911 + row * 353 + frame * 17);
if (jitter < 0.18) index += grSeeded(column * 1193 + row * 281) < 0.5 ? -1 : 1;
index = Math.max(0, Math.min(chars.length - 1, index));
const effects = grEffectSettings();
const threshold = (effects.asciiHighlightThreshold || 100) / 100;
if (chars[index] === " " && tone >= Math.max(0.58, threshold - 0.14)) {
index = Math.max(1, Math.min(chars.length - 1, 1));
}
return chars[index] || " ";
}
function grEdgeGlyphFromStyle(style) {
if (style === "6") return "|";
if (style === "7") return "-";
if (style === "8") return "/";
if (style === "9") return "\\";
return null;
}
function grIsEdgeStyle(style) {
return style === "6" || style === "7" || style === "8" || style === "9";
}
function grIsDenseHighlightStyle(style) {
return style === "A" || style === "B" || style === "C" || style === "D";
}
function grEffectiveStyle(rawStyle, tone) {
const storageMode = SIGNAL_RITUAL_ENGINE.visualRenderer?.storageMode || SIGNAL_RITUAL_ENGINE.storageMode;
if (storageMode === "derived-glyphs-from-tone-style") {
if (rawStyle === "1" || rawStyle === "2" || rawStyle === "3" || rawStyle === "4" || grIsDenseHighlightStyle(rawStyle) || grIsEdgeStyle(rawStyle)) return rawStyle;
return tone < 0.08 ? "5" : "0";
}
return rawStyle || "0";
}
function grGeneratedToneFrame(storedToneFrames, displayedFrame) {
const source = SIGNAL_RITUAL_ENGINE.keyframeSourceFrames.map((frame) => frame - 1);
let rightSlot = source.findIndex((frame) => frame >= displayedFrame);
if (rightSlot < 0) rightSlot = source.length - 1;
const leftSlot = Math.max(0, rightSlot - (source[rightSlot] === displayedFrame ? 0 : 1));
const leftFrame = source[leftSlot];
const rightFrame = source[rightSlot];
const a = storedToneFrames[leftSlot] || "";
const b = storedToneFrames[rightSlot] || a;
const t = rightFrame === leftFrame ? 0 : (displayedFrame - leftFrame) / (rightFrame - leftFrame);
const eased = t * t * (3 - 2 * t);
let output = "";
const max = Math.max(a.length, b.length);
for (let i = 0; i < max; i += 1) {
const ca = a[i] || "0";
const cb = b[i] || ca;
if (ca === "\n" || cb === "\n") output += "\n";
else {
const av = parseInt(ca, 16);
const bv = parseInt(cb, 16);
const blended = Math.max(0, Math.min(15, Math.round(av + (bv - av) * eased)));
output += blended.toString(16).toUpperCase();
}
}
return output;
}
function grGeneratedStyleFrame(storedStyleFrames, displayedFrame) {
const source = SIGNAL_RITUAL_ENGINE.keyframeSourceFrames.map((frame) => frame - 1);
let rightSlot = source.findIndex((frame) => frame >= displayedFrame);
if (rightSlot < 0) rightSlot = source.length - 1;
const leftSlot = Math.max(0, rightSlot - (source[rightSlot] === displayedFrame ? 0 : 1));
const leftFrame = source[leftSlot];
const rightFrame = source[rightSlot];
if (rightFrame === leftFrame) return storedStyleFrames[leftSlot] || "";
const t = (displayedFrame - leftFrame) / (rightFrame - leftFrame);
return t < 0.5 ? storedStyleFrames[leftSlot] || "" : storedStyleFrames[rightSlot] || storedStyleFrames[leftSlot] || "";
}
function grMix(a, b, amount) {
return [
Math.round(a[0] + (b[0] - a[0]) * amount),
Math.round(a[1] + (b[1] - a[1]) * amount),
Math.round(a[2] + (b[2] - a[2]) * amount),
];
}
function grPaletteColor(value) {
const renderer = SIGNAL_RITUAL_ENGINE.visualRenderer;
const ramp = renderer.paletteColors || [[255, 255, 255]];
const v = renderer.paletteInvert ? 1 - value : value;
const scaled = Math.max(0, Math.min(1, v)) * (ramp.length - 1);
const start = Math.floor(scaled);
const end = Math.min(ramp.length - 1, start + 1);
return grMix(ramp[start], ramp[end], scaled - start);
}
function grLuminance(color) {
return (color[0] * 0.2126 + color[1] * 0.7152 + color[2] * 0.0722) / 255;
}
function grPreserveLuminance(color, targetTone) {
const target = Math.max(0, Math.min(1, targetTone));
const current = Math.max(0, Math.min(1, grLuminance(color)));
if (current <= 0.0001) {
const gray = Math.round(target * 255);
return [gray, gray, gray];
}
if (target <= current) {
const ratio = target / current;
return color.map((channel) => Math.max(0, Math.min(255, Math.round(channel * ratio))));
}
const amount = Math.min(1, (target - current) / Math.max(0.0001, 1 - current));
return color.map((channel) => Math.max(0, Math.min(255, Math.round(channel + (255 - channel) * amount))));
}
function grApplyPostAsciiChannel(value, contrastFactor, midtoneAmount) {
const contrasted = Math.max(0, Math.min(255, contrastFactor * (value - 128) + 128));
if (midtoneAmount === 0) return contrasted;
const normalized = contrasted / 255;
const midtoneMask = 4 * normalized * (1 - normalized);
return Math.max(0, Math.min(255, contrasted + midtoneAmount * midtoneMask * 96));
}
function grApplyPostAsciiToneToColor(color, brightness = 0, midtones = 0) {
const contrast = Math.max(-100, Math.min(100, Number(brightness) || 0));
const factor = (259 * (contrast + 255)) / (255 * (259 - contrast));
const midtoneAmount = Math.max(-1, Math.min(1, (Number(midtones) || 0) / 100));
return color.map((channel) => grApplyPostAsciiChannel(channel, factor, midtoneAmount));
}
function grRawInkColor(tone) {
const renderer = SIGNAL_RITUAL_ENGINE.visualRenderer;
if (renderer.inkMode === "bw") return [245, 245, 235];
const floor = renderer.rendererTuning?.paletteToneFloor ?? 0.05;
const value = Math.max(floor, tone);
const color = grPaletteColor(value);
return renderer.palettePreserveLuminance ? grPreserveLuminance(color, value) : color;
}
function grFinalToneColor(color) {
const effects = SIGNAL_RITUAL_ENGINE.visualRenderer.effects || {};
return grApplyPostAsciiToneToColor(color, effects.asciiBrightness, effects.asciiMidtones);
}
function grInkColor(tone) {
return grFinalToneColor(grRawInkColor(tone));
}
function grHighlightInkColor(tone, highlightFill, isHighlightMark, isHeavyInk, isDenseHighlight) {
const color = grRawInkColor(tone);
const effects = SIGNAL_RITUAL_ENGINE.visualRenderer.effects || {};
const threshold = (effects.asciiHighlightThreshold || 100) / 100;
const protectedTopToneHighlight = tone >= 0.92 && (isDenseHighlight || isHighlightMark || isHeavyInk);
const toneLift = grSmoothstep(Math.max(0.48, threshold - 0.2), 1, tone) * (0.72 + highlightFill * 0.34);
const denseLift = isDenseHighlight ? 0.68 + grSmoothstep(0.66, 0.9, tone) * 0.24 : 0;
const lift = Math.max(
highlightFill * 0.72,
toneLift,
denseLift,
isHighlightMark ? 0.62 : 0,
isHeavyInk ? 0.52 : 0,
);
if (lift <= 0) return grFinalToneColor(color);
const cap = isDenseHighlight || isHighlightMark || isHeavyInk || tone >= 0.78 ? 0.98 : 0.78;
const liftedColor = color.map((channel) => Math.max(0, Math.min(255, Math.round(channel + (255 - channel) * Math.min(cap, lift)))));
return protectedTopToneHighlight ? liftedColor : grFinalToneColor(liftedColor);
}
function grRgbString(color) {
return "rgb(" + color[0] + "," + color[1] + "," + color[2] + ")";
}
function grBase64Bytes(encoded) {
const text = atob(encoded);
const bytes = new Uint8Array(text.length);
for (let i = 0; i < text.length; i += 1) bytes[i] = text.charCodeAt(i);
return bytes;
}
function grDecodeJson(encoded) {
const bytes = grBase64Bytes(encoded);
let text = "";
for (let i = 0; i < bytes.length; i += 1) text += String.fromCharCode(bytes[i]);
return JSON.parse(text);
}
class GrBitReader {
constructor(bytes) {
this.bytes = bytes;
this.byteIndex = 0;
this.bitIndex = 0;
}
read(bits) {