Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <title>Semantic Signature Scanner</title>
- <style>
- body { font-family: monospace; background: #111; color: #eee; padding: 20px; }
- canvas { border: 1px solid #444; image-rendering: pixelated; }
- #output { margin-top: 20px; white-space: pre; font-size: 14px; line-height: 1.4; }
- </style>
- </head>
- <body>
- <h1>🧠 Semantic Signature Scanner</h1>
- <input type="file" id="imageInput" accept="image/*" />
- <canvas id="semanticCanvas" width="512" height="512"></canvas>
- <div id="output"></div>
- <script>
- const canvas = document.getElementById("semanticCanvas");
- const ctx = canvas.getContext("2d");
- const output = document.getElementById("output");
- const gridSize = 7;
- let semanticDictionary = {};
- // Load dictionary
- async function loadDictionary() {
- const res = await fetch("dictionary.json");
- semanticDictionary = await res.json();
- }
- // Resolve RGB to phrase
- function resolvePhrase(r, g, b) {
- for (let condition in semanticDictionary) {
- const expr = condition.replace(/R/g, r).replace(/G/g, g).replace(/B/g, b);
- if (eval(expr)) return semanticDictionary[condition];
- }
- return "—";
- }
- // Extract semantic grid
- function extractSemanticGrid(ctx, width, height, gridSize) {
- const imageData = ctx.getImageData(0, 0, width, height);
- const data = imageData.data;
- const grid = [];
- for (let y = 0; y < height; y += gridSize) {
- const row = [];
- for (let x = 0; x < width; x += gridSize) {
- let r = 0, g = 0, b = 0, count = 0;
- for (let dy = 0; dy < gridSize; dy++) {
- for (let dx = 0; dx < gridSize; dx++) {
- const px = ((y + dy) * width + (x + dx)) * 4;
- r += data[px]; g += data[px + 1]; b += data[px + 2]; count++;
- }
- }
- r = Math.floor(r / count);
- g = Math.floor(g / count);
- b = Math.floor(b / count);
- row.push(resolvePhrase(r, g, b));
- }
- grid.push(row);
- }
- return grid;
- }
- // Overlay phrases on canvas
- function drawOverlay(grid, gridSize) {
- for (let y = 0; y < grid.length; y++) {
- for (let x = 0; x < grid[y].length; x++) {
- const phrase = grid[y][x];
- ctx.fillStyle = "rgba(0,0,0,0.6)";
- ctx.fillRect(x * gridSize, y * gridSize, gridSize, gridSize);
- ctx.fillStyle = "white";
- ctx.font = "6px monospace";
- ctx.fillText(phrase, x * gridSize + 1, y * gridSize + 6);
- }
- }
- }
- // Detect spooky clusters
- function detectPhraseClusters(grid, targetPhrase, minLength = 3) {
- const clusters = [];
- const rows = grid.length;
- const cols = grid[0].length;
- // Horizontal
- for (let y = 0; y < rows; y++) {
- let count = 0;
- for (let x = 0; x < cols; x++) {
- count = grid[y][x] === targetPhrase ? count + 1 : 0;
- if (count >= minLength) {
- clusters.push(`"${targetPhrase}" horizontally at row ${y}, cols ${x - count + 1}–${x}`);
- }
- }
- }
- // Vertical
- for (let x = 0; x < cols; x++) {
- let count = 0;
- for (let y = 0; y < rows; y++) {
- count = grid[y][x] === targetPhrase ? count + 1 : 0;
- if (count >= minLength) {
- clusters.push(`"${targetPhrase}" vertically at col ${x}, rows ${y - count + 1}–${y}`);
- }
- }
- }
- // Diagonal ↘
- for (let y = 0; y <= rows - minLength; y++) {
- for (let x = 0; x <= cols - minLength; x++) {
- let match = true;
- for (let i = 0; i < minLength; i++) {
- if (grid[y + i][x + i] !== targetPhrase) {
- match = false;
- break;
- }
- }
- if (match) {
- clusters.push(`"${targetPhrase}" diagonally ↘ from (${x}, ${y})`);
- }
- }
- }
- return clusters;
- }
- // Handle image input
- document.getElementById("imageInput").addEventListener("change", async (e) => {
- await loadDictionary();
- const file = e.target.files[0];
- if (!file) return;
- const img = new Image();
- img.onload = () => {
- canvas.width = img.width;
- canvas.height = img.height;
- ctx.clearRect(0, 0, canvas.width, canvas.height);
- ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
- const signatureGrid = extractSemanticGrid(ctx, canvas.width, canvas.height, gridSize);
- drawOverlay(signatureGrid, gridSize);
- output.innerText = signatureGrid.map(row => row.join(" ")).join("\n");
- };
- img.src = URL.createObjectURL(file);
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment