返回资讯中心
外部精选
软件工程
#开发者实时流

Id|Le

// Gloamhold starts moodier (fog); pages and labs start from a copy of Home's settings.

Hacker News 最新nico2026/11/1 · 17 天前30 分钟阅读

以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。

'. // Gloamhold starts moodier (fog); pages and labs start from a copy of Home's settings. const KEEP_WORLD = { ...DEFAULT_WORLD, id: 'keep-0', weather: 'fog', wint: 0.55 }; let worldAt = 'home'; const wkey = b => worldAt === 'home' ? b : b + '@' + worldAt; let lastWorldText = null; if (!world.features) world.features = genFeatures(world); function saveWorld() { try { localStorage.setItem(wkey('arena.world'), JSON.stringify(world)); } catch (e) {} const el = $('#worldInfo'); if (el) el.textContent = ${world.id} · ${world.layout} · tilt ±${world.tilt ?? 18}° · ${world.font} ${world.size}px · ink ${world.inkSat ? 'hue ' + world.ink : 'plain'} · weather ${WEATHER_NAMES[world.weather] || world.weather} ${Math.round((world.wint ?? .35) * 100)}%; const wl = $('#weatherLabel'); if (wl) wl.textContent = '☁ ' + (WEATHER_NAMES[world.weather] || world.weather); if (window.__weather) window.__weather.set(world.weather, world.wint ?? .35, (world.wx || {})[world.weather]); } function worldFont() { return { serif: "Georgia,'Times New Roman',serif", mono: 'ui-monospace,Menlo,monospace', sans: 'system-ui,sans-serif' }[world.font] || 'Georgia,serif'; } function keepEvolved(told) { if (told && told.length) say('lab', '🕯️ Gloamhold evolved: ' + told.join('; '), 'lab'); } function genFeatures(w) { const r = () => Math.random(), F = []; const n = w.featureCount ?? 5; for (let i = 0; i +(v * Math.exp(gauss() * r)).toFixed(2); const w = { ...world, id: 'world-' + Date.now().toString(36).slice(-4) }; if (Math.random() x !== world.weather)); w.wint = Math.max(0.1, Math.min(1, +((world.wint ?? 0.35) * Math.exp(gauss() * 0.35)).toFixed(2))); if (Math.random() f.len / 2 - 8) { w.x -= ca * f.len * 0.98; w.y -= sa * f.len * 0.98; } } } // packet stream: a conveyor that loops else if (f.type === 'hole' && Math.hypot(dx, dy) hw + ext || Math.abs(y - cam.y) > hh + ext) continue; if (f.type === 'stream') { const ca = Math.cos(f.a), sa = Math.sin(f.a), x1 = x - ca * f.len / 2, y1 = y - sa * f.len / 2, x2 = x + ca * f.len / 2, y2 = y + sa * f.len / 2; s += ``; } else if (f.type === 'well') { for (let k = 0; k ; s += latency ${Math.round(f.r * 3)}ms; } else if (f.type === 'hole') s += 404; else s += cache · no wind; } return s; } function layTerrain(text, title) { lastWorldText = { text, title }; return layPage(text, title, document.getElementById('additive') && document.getElementById('additive').checked && words.some(w => w.terrain)); clearTerrain(); const r = arenaEl.getBoundingClientRect(), W = r.width, H = r.height; const sentences = String(text).replace(/\s+/g, ' ').split(/(? se.split(' ').map(w => ({ raw: w.replace(/^[^\w']+|[^\w']+$/g, ''), }) ).filter(o => /^[A-Za-z][A-Za-z'-]{0,17}$/.test(o.raw))).filter(a => a.length); let flat = []; sentences.forEach((se, si) => se.forEach(o => flat.push({ ...o, si }))); flat = flat.slice(0, 220); if (!flat.length) return; const freq = {}; flat.forEach(o => { const k = o.raw.toLowerCase(); freq[k] = (freq[k] || 0) + 1; }); const nIsl = Math.max(2, Math.min(7, Math.round(flat.length / 35))), centers = []; for (let i = 0; i Math.hypot(o.x - c.x, o.y - c.y))) : 1e9; if (d > bd) { bd = d; best = c; } } centers.push(best); } const per = Math.ceil(flat.length / nIsl), counts = new Array(nIsl).fill(0); centers.forEach((c, i) => { const isl = document.createElement('div'); isl.className = 'island'; const rad = 40 + Math.sqrt(per) * 13; isl.style.cssText = left:${c.x - rad}px;top:${c.y - rad * 0.8}px;width:${rad * 2}px;height:${rad * 1.6}px;border-radius:${45 + Math.random() * 10}% ${55 - Math.random() * 10}% ${50 + Math.random() * 8}% ${48 - Math.random() * 8}%;transform:rotate(${(Math.random() - .5) * 40}deg); floor.insertBefore(isl, floor.firstChild); }); flat.forEach((o, n) => { const i = Math.min(nIsl - 1, Math.floor(n / per)), c = centers[i], k = counts[i]++, ang = k * 2.39996 + i, rad = 18 * Math.sqrt(k + 0.6); const x = Math.max(16, Math.min(W - 16, c.x + Math.cos(ang) * rad * 1.35 + (Math.random() - .5) * 6)), y = Math.max(14, Math.min(H - 14, c.y + Math.sin(ang) * rad * 0.95 + (Math.random() - .5) * 6)); const low = o.raw.toLowerCase(), ww = addWord(low, x, y); ww.terrain = true; ww.el.classList.add('terrain'); const kind = GRASS.has(low) || low.length = 8 ? 'rock' : 'soil'; ww.kind = kind; ww.el.classList.add('t-' + kind); if (freq[low] > 1 && kind !== 'grass') ww.el.style.fontSize = Math.min(18, 11 + freq[low] * 1.5) + 'px'; ww.rot = (Math.random() - .5) * (kind === 'grass' ? 30 : 8); place(ww); }); say('lab', 'world: ' + (title ? '"' + title.slice(0, 60) + '", ' : '') + flat.length + ' words on ' + nIsl + ' islands', 'lab'); logEvent('terrain', { n: flat.length, islands: nIsl, url: !!title }); oracleComment(pick([New world. ${nIsl} islands of words, and the legs have noticed, Someone grew a landscape in my room. The crawler will eat half of it, My room has islands now. ${title ? 'They used to be ' + title.slice(0, 40) : 'Do not ask me to read them'}]), 'terrain'); } // meaning map: words that keep company in the corpus settle together (the chat page's 32-d co-occurrence vectors); each group of // meaning becomes a landform with its own shape — mound, ring, river, spiral, patch — so every page grows a different but consistent world let ASSOC = null; fetch('assoc_v1.json').then(r => r.json()).then(a => { a.idx = {}; a.words.forEach((w, i) => { a.idx[w] = i; }); ASSOC = a; }).catch(() => {}); function layMeaning(toks, put, patch, mound, rnd, rot, W, H) { if (!ASSOC) { toks.forEach(raw => put(raw, rnd(0, W), rnd(0, H), rot())); return; } const vecOf = w => { const i = ASSOC.idx[w.toLowerCase()]; return i == null ? null : ASSOC.vec[i]; }, D = ASSOC.dim; const items = toks.map(raw => ({ raw, v: vecOf(raw) })), known = items.filter(o => o.v); const K = Math.max(3, Math.min(9, world.mounds || 6)); let cent = known.slice().sort(() => Math.random() - .5).slice(0, K).map(o => o.v.slice()); for (let it = 0; it new Array(D).fill(0)), cnt = cent.map(() => 0); for (const o of known) { let b = 0, bd = -1e9; cent.forEach((c, j) => { let d = 0; for (let k = 0; k bd) { bd = d; b = j; } }); o.c = b; cnt[b]++; for (let k = 0; k { const n = Math.hypot(...sm) || 1; return cnt[j] ? sm.map(x => x / n) : cent[j]; }); } // place the groups: centroids projected to 2-D (first two principal directions of the centroids), stretched over the whole torus const mean = new Array(D).fill(0); cent.forEach(c => c.forEach((x, k) => mean[k] += x / cent.length)); const Cc = cent.map(c => c.map((x, k) => x - mean[k])); const pc = () => { let v = Array.from({ length: D }, () => Math.random() - .5); for (let i = 0; i a + x * v[k], 0); for (let k = 0; k x / n); } return v; }; const p1 = pc(); const Cd = Cc.map(c => { const d = c.reduce((a, x, k) => a + x * p1[k], 0); return c.map((x, k) => x - d * p1[k]); }); const p2 = (() => { let v = Array.from({ length: D }, () => Math.random() - .5); for (let i = 0; i a + x * v[k], 0); for (let k = 0; k x / n); } return v; })(); const P = Cc.map(c => [c.reduce((a, x, k) => a + x * p1[k], 0), c.reduce((a, x, k) => a + x * p2[k], 0)]), mx = [Math.min(...P.map(p => p[0])), Math.max(...P.map(p => p[0]))], my = [Math.min(...P.map(p => p[1])), Math.max(...P.map(p => p[1]))]; const centers = P.map(([x, y]) => ({ x: W * (0.12 + 0.76 * (x - mx[0]) / ((mx[1] - mx[0]) || 1)) + rnd(-60, 60), y: H * (0.12 + 0.76 * (y - my[0]) / ((my[1] - my[0]) || 1)) + rnd(-60, 60) })); { let last = null; for (const o of items) { if (o.v) last = o.c; else if (last != null && Math.random() { const group = items.filter(o => o.c === j).map(o => o.raw), c = centers[j], shape = SHAPES[(j * 7 + (world.ink || 0) + (world.mounds || 0)) % SHAPES.length]; if (!group.length) return; if (shape === 'mound') mound(group, c.x, c.y); else if (shape === 'patch') patch(group, c.x, c.y, rnd(180, 320)); else if (shape === 'ring') group.forEach((raw, i) => { const a = i / group.length * Math.PI * 2, R = 40 + group.length * 4; put(raw, c.x + Math.cos(a) * R * 1.3, c.y + Math.sin(a) * R, (a * 180 / Math.PI + 90) % 180 - 90 > 0 ? rot() : -rot()); }); else if (shape === 'river') { const ang = rnd(0, Math.PI), L = group.length * 26; group.forEach((raw, i) => { const u = i / Math.max(1, group.length - 1) - .5, px = c.x + Math.cos(ang) * u * L - Math.sin(ang) * Math.sin(u * 7) * 30, py = c.y + Math.sin(ang) * u * L + Math.cos(ang) * Math.sin(u * 7) * 30; put(raw, px, py, ang * 180 / Math.PI * 0.4 + rot() * 0.3); }); } else if (shape === 'wave') group.forEach((raw, i) => { const u = i * 30 - group.length * 15; put(raw, c.x + u, c.y + Math.sin(i * 0.7) * 40, Math.cos(i * 0.7) * 35); }); else if (shape === 'stack') group.forEach((raw, i) => put(raw, c.x + (i % 2 ? 10 : -10), c.y + (i - group.length / 2) * 20, 90)); else if (shape === 'burst') group.forEach((raw, i) => { const a = i / group.length * Math.PI * 2, R = 30 + (i % 3) * 38; put(raw, c.x + Math.cos(a) * R, c.y + Math.sin(a) * R, a * 180 / Math.PI); }); else if (shape === 'cross') group.forEach((raw, i) => { const arm = i % 4, d = 24 + Math.floor(i / 4) * 26, dir = [[1, 0], [0, 1], [-1, 0], [0, -1]][arm]; put(raw, c.x + dir[0] * d, c.y + dir[1] * d, arm % 2 ? 90 : 0); }); else group.forEach((raw, i) => { const a = i * 0.55, R = 12 + i * 5; put(raw, c.x + Math.cos(a) * R, c.y + Math.sin(a) * R, a * 180 / Math.PI + 90); }); }); items.filter(o => o.c == null).forEach(o => put(o.raw, rnd(0, W), rnd(0, H), rot())); // words the vectors do not know: the wilds } function layPage(text, title, additive) { // spread the text over the whole world: mix (patches of text + mounds + strays), mounds, spread, or page; one size, one colour, varied tilt if (!additive) clearTerrain(); const vw0 = viewSize(), W = additive ? Math.min(SPACE.W, vw0.w / cam.z * 1.5) : SPACE.W, H = additive ? Math.min(SPACE.H, vw0.h / cam.z * 1.5) : SPACE.H, OX = additive ? cam.x - W / 2 : 0, OY = additive ? cam.y - H / 2 : 0, fs = world.size, lh = fs * world.line, cw = fs * (world.font === 'mono' ? 0.62 : 0.5), tilt = world.tilt ?? 18; const toks = String(text).replace(/\s+/g, ' ').split(' ').map(w => w.replace(/^[^\w']+|[^\w']+$/g, '')).filter(w => /^[A-Za-z][A-Za-z'-]{0,17}$/.test(w)).slice(0, Math.round(320 * world.density)); const put = (raw, x, y, rot) => { const ww = addWord(raw.toLowerCase(), x + OX, y + OY); ww.terrain = true; ww.el.classList.add('terrain', 't-page'); ww.el.style.font = ${fs}px/1 ${worldFont()}; if (world.inkSat) ww.el.style.color = hsl(${world.ink},${world.inkSat}%,55%); ww.rot = rot; place(ww); }; const rnd = (a, b) => a + Math.random() * (b - a), rot = () => (Math.random() - .5) * 2 * tilt; const patch = (list, cx, cy, width) => { let x = cx - width / 2, y = cy; const r0 = (Math.random() - .5) * tilt * 0.5; for (const raw of list) { const w = raw.length * cw + fs * 0.45; if (x + w > cx + width / 2) { x = cx - width / 2; y += lh; } put(raw, x + w / 2, y, r0 + (Math.random() - .5) * 4); x += w; } }; const mound = (list, cx, cy) => list.forEach((raw, i) => { const a = i * 2.39996, rr = 9 * Math.sqrt(i + 1); put(raw, cx + Math.cos(a) * rr * 1.6 + rnd(-6, 6), cy + Math.sin(a) * rr + rnd(-4, 4), rot() * 2); }); let i = 0; const take = n => toks.slice(i, i += n); if (world.layout === 'meaning') { layMeaning(toks, put, patch, mound, rnd, rot, W, H); } else if (world.layout === 'page') patch(toks, W / 2, 60, W - 2 * world.margin); else if (world.layout === 'spread') toks.forEach(raw => put(raw, rnd(0, W), rnd(0, H), rot())); else if (world.layout === 'mounds') { const k = Math.max(2, world.mounds || 5), per = Math.ceil(toks.length / k); for (let m = 0; m put(raw, rnd(0, W), rnd(0, H), rot())); } } say('lab', 'world: ' + (title ? '"' + title.slice(0, 60) + '", ' : '') + toks.length + ' words, ' + world.layout + ' (pan to explore, the edges wrap)', 'lab'); logEvent('terrain', { n: toks.length, layout: world.layout, world: world.id, url: !!title }); oracleComment(pick([New floor. Words everywhe

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →