|
|
@@ -48,7 +48,7 @@ function mkSvgEl(tag, attrs = {}, parent) {
|
|
|
return e
|
|
|
}
|
|
|
|
|
|
-/* ---------- fondo PCB (placa de circuito con señales) ---------- */
|
|
|
+/* ---------- fondo netflow (ondas de tráfico, calmado) ---------- */
|
|
|
function mulberry32(seed) {
|
|
|
let a = seed >>> 0
|
|
|
return function () {
|
|
|
@@ -66,224 +66,55 @@ function initBackgroundCanvas() {
|
|
|
const reduce = reduceMotion
|
|
|
const dpr = Math.min(window.devicePixelRatio || 1, 2)
|
|
|
let w = 0, h = 0
|
|
|
- let chips = [], traces = [], pulses = [], vias = []
|
|
|
- let mx = -1e4, my = -1e4, tmx = -1e4, tmy = -1e4
|
|
|
- const rand = mulberry32(0x5EED)
|
|
|
- const G = 12 // rejilla base de la placa
|
|
|
-
|
|
|
- const pick = (arr) => arr[Math.floor(rand() * arr.length)]
|
|
|
+ let layers = []
|
|
|
+ const rand = mulberry32(0x51A7E)
|
|
|
const alphaColor = (c, a) => c.replace(')', ` / ${a})`)
|
|
|
|
|
|
- function edgePoint(c) {
|
|
|
- const side = Math.floor(rand() * 4)
|
|
|
- if (side === 0) return { x: c.x + c.w / 2, y: c.y - 2 }
|
|
|
- if (side === 1) return { x: c.x - 2, y: c.y + c.h / 2 }
|
|
|
- if (side === 2) return { x: c.x + c.w / 2, y: c.y + c.h + 2 }
|
|
|
- return { x: c.x + c.w + 2, y: c.y + c.h / 2 }
|
|
|
- }
|
|
|
-
|
|
|
- function chamfer(a, b, c, d) {
|
|
|
- const dx1 = Math.sign(b.x - a.x), dy1 = Math.sign(b.y - a.y)
|
|
|
- const dx2 = Math.sign(c.x - b.x), dy2 = Math.sign(c.y - b.y)
|
|
|
- if (dx1 === dx2 && dy1 === dy2) return [b]
|
|
|
- if (dx1 === -dx2 && dy1 === -dy2) return [b]
|
|
|
- const e = Math.min(d, Math.abs(b.x - a.x) / 2, Math.abs(b.y - a.y) / 2, Math.abs(c.x - b.x) / 2, Math.abs(c.y - b.y) / 2)
|
|
|
- if (e < 2) return [b]
|
|
|
- return [
|
|
|
- { x: b.x - dx1 * e, y: b.y - dy1 * e },
|
|
|
- { x: b.x + dx2 * e, y: b.y + dy2 * e },
|
|
|
- ]
|
|
|
- }
|
|
|
-
|
|
|
- function routePts(sx, sy, ex, ey) {
|
|
|
- const pts = [{ x: sx, y: sy }]
|
|
|
- const style = rand()
|
|
|
- if (style < 0.32) {
|
|
|
- pts.push({ x: ex, y: sy }, { x: ex, y: ey })
|
|
|
- } else if (style < 0.64) {
|
|
|
- pts.push({ x: sx, y: ey }, { x: ex, y: ey })
|
|
|
- } else {
|
|
|
- const k = 0.35 + rand() * 0.3
|
|
|
- const mx0 = sx + (ex - sx) * k
|
|
|
- const my0 = sy + (ey - sy) * k
|
|
|
- if (rand() < 0.5) pts.push({ x: mx0, y: sy }, { x: mx0, y: ey })
|
|
|
- else pts.push({ x: sx, y: my0 }, { x: ex, y: my0 })
|
|
|
- pts.push({ x: ex, y: ey })
|
|
|
- }
|
|
|
- if (pts.length > 2) {
|
|
|
- const ch = 5 + rand() * 6
|
|
|
- const out = [pts[0]]
|
|
|
- for (let i = 1; i < pts.length - 1; i++) out.push(...chamfer(pts[i - 1], pts[i], pts[i + 1], ch))
|
|
|
- out.push(pts[pts.length - 1])
|
|
|
- return out
|
|
|
- }
|
|
|
- return pts
|
|
|
- }
|
|
|
-
|
|
|
- function buildLayout() {
|
|
|
- chips = []; traces = []; pulses = []; vias = []
|
|
|
- const count = Math.min(18, Math.max(8, Math.round((w * h) / 150000)))
|
|
|
- let guard = 0
|
|
|
- while (chips.length < count && guard++ < 800) {
|
|
|
- const cw = 18 + Math.floor(rand() * 14)
|
|
|
- const chh = Math.round(cw * (0.7 + rand() * 0.6))
|
|
|
- const x = Math.round((18 + rand() * (w - 36 - cw)) / G) * G
|
|
|
- const y = Math.round((18 + rand() * (h - 36 - chh)) / G) * G
|
|
|
- const clash = chips.some((p) => Math.abs(p.x - x) < p.w * 0.7 + cw * 0.7 + 28 && Math.abs(p.y - y) < p.h * 0.7 + chh * 0.7 + 28)
|
|
|
- if (clash) continue
|
|
|
- chips.push({ x, y, w: cw, h: chh, kind: rand() < 0.18 ? 'gw' : 'chip' })
|
|
|
- }
|
|
|
- const pairs = Math.min(chips.length * 2, 34)
|
|
|
- for (let i = 0; i < pairs && chips.length > 1; i++) {
|
|
|
- const a = pick(chips), b = pick(chips)
|
|
|
- if (a === b) continue
|
|
|
- const pa = edgePoint(a), pb = edgePoint(b)
|
|
|
- traces.push({ pts: routePts(pa.x, pa.y, pb.x, pb.y) })
|
|
|
- vias.push(pa, pb)
|
|
|
- }
|
|
|
- traces.forEach((tr) => {
|
|
|
- tr.lens = [0]
|
|
|
- let acc = 0
|
|
|
- for (let i = 1; i < tr.pts.length; i++) {
|
|
|
- acc += Math.hypot(tr.pts[i].x - tr.pts[i - 1].x, tr.pts[i].y - tr.pts[i - 1].y)
|
|
|
- tr.lens.push(acc)
|
|
|
- }
|
|
|
- tr.total = acc
|
|
|
- })
|
|
|
- const colors = ['accent', 'tunnel', 'ok', 'info', 'warn']
|
|
|
- traces.forEach((tr, ti) => {
|
|
|
- if (tr.total < 70) return
|
|
|
- const n = tr.total > 300 ? 2 : 1
|
|
|
- for (let k = 0; k < n; k++) pulses.push({ ti, off: rand(), dur: 2.4 + rand() * 3.6, color: pick(colors) })
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- function ptAt(tr, dist) {
|
|
|
- const pts = tr.pts
|
|
|
- for (let i = 1; i < pts.length; i++) {
|
|
|
- const s = tr.lens[i - 1], e = tr.lens[i]
|
|
|
- if (dist <= e) {
|
|
|
- const f = (e - s) ? (dist - s) / (e - s) : 0
|
|
|
- return { x: pts[i - 1].x + (pts[i].x - pts[i - 1].x) * f, y: pts[i - 1].y + (pts[i].y - pts[i - 1].y) * f }
|
|
|
- }
|
|
|
- }
|
|
|
- const last = pts[pts.length - 1]
|
|
|
- return { x: last.x, y: last.y }
|
|
|
+ function buildLayers() {
|
|
|
+ const palette = ['accent', 'tunnel', 'ok']
|
|
|
+ layers = palette.map((color, i) => ({
|
|
|
+ color,
|
|
|
+ base: 0.55 + i * 0.17,
|
|
|
+ amp: 22 + rand() * 26,
|
|
|
+ freq: 0.004 + rand() * 0.0025,
|
|
|
+ speed: 0.00006 + rand() * 0.00009,
|
|
|
+ phase: rand() * Math.PI * 2,
|
|
|
+ peak: 0.08 + rand() * 0.035,
|
|
|
+ drift: 6 + rand() * 10,
|
|
|
+ }))
|
|
|
}
|
|
|
|
|
|
- function roundRectPath(x, y, rw, rh, r) {
|
|
|
- ctx.beginPath()
|
|
|
- ctx.moveTo(x + r, y)
|
|
|
- ctx.arcTo(x + rw, y, x + rw, y + rh, r)
|
|
|
- ctx.arcTo(x + rw, y + rh, x, y + rh, r)
|
|
|
- ctx.arcTo(x, y + rh, x, y, r)
|
|
|
- ctx.arcTo(x, y, x + rw, y, r)
|
|
|
- ctx.closePath()
|
|
|
+ function sample(l, x, t) {
|
|
|
+ return Math.sin(x * l.freq + t * l.speed + l.phase) * l.amp * 0.62
|
|
|
+ + Math.sin(x * l.freq * 0.51 + t * l.speed * 0.73 + l.phase * 1.7) * l.amp * 0.38
|
|
|
}
|
|
|
|
|
|
- function drawStatic() {
|
|
|
- const border = getCssVar('border')
|
|
|
- const borderStrong = getCssVar('border-strong')
|
|
|
- const elevated = getCssVar('elevated')
|
|
|
- const accent = getCssVar('accent')
|
|
|
+ function render(t) {
|
|
|
ctx.clearRect(0, 0, w, h)
|
|
|
-
|
|
|
- // rejilla de vías de fondo
|
|
|
- ctx.fillStyle = border
|
|
|
- ctx.globalAlpha = 0.05
|
|
|
- for (let x = G * 4; x < w; x += G * 4) {
|
|
|
- for (let y = G * 4; y < h; y += G * 4) ctx.fillRect(x - 0.6, y - 0.6, 1.2, 1.2)
|
|
|
- }
|
|
|
- ctx.globalAlpha = 1
|
|
|
-
|
|
|
- // pistas base
|
|
|
- ctx.lineCap = 'round'
|
|
|
- ctx.lineJoin = 'round'
|
|
|
- ctx.strokeStyle = borderStrong
|
|
|
- ctx.globalAlpha = 0.18
|
|
|
- ctx.lineWidth = 1
|
|
|
- for (const tr of traces) {
|
|
|
- ctx.beginPath()
|
|
|
- ctx.moveTo(tr.pts[0].x, tr.pts[0].y)
|
|
|
- for (let i = 1; i < tr.pts.length; i++) ctx.lineTo(tr.pts[i].x, tr.pts[i].y)
|
|
|
- ctx.stroke()
|
|
|
- }
|
|
|
- ctx.globalAlpha = 1
|
|
|
-
|
|
|
- // vías / pads
|
|
|
- for (const v of vias) {
|
|
|
- ctx.fillStyle = accent
|
|
|
- ctx.globalAlpha = 0.35
|
|
|
+ const span = 8
|
|
|
+ for (const l of layers) {
|
|
|
+ const base = l.base * h + Math.sin(t * 0.00005 + l.phase * 2) * l.drift
|
|
|
+ const col = getCssVar(l.color)
|
|
|
+ // banda: de la onda hasta el fondo, con degradado que se desvanece hacia abajo
|
|
|
+ const g = ctx.createLinearGradient(0, base, 0, h)
|
|
|
+ g.addColorStop(0, alphaColor(col, l.peak))
|
|
|
+ g.addColorStop(0.5, alphaColor(col, l.peak * 0.35))
|
|
|
+ g.addColorStop(1, alphaColor(col, 0))
|
|
|
ctx.beginPath()
|
|
|
- ctx.arc(v.x, v.y, 2.4, 0, Math.PI * 2)
|
|
|
+ ctx.moveTo(-span, base + sample(l, -span, t))
|
|
|
+ for (let x = 0; x <= w + span; x += span) ctx.lineTo(x, base + sample(l, x, t))
|
|
|
+ ctx.lineTo(w + span, h + 20)
|
|
|
+ ctx.lineTo(-span, h + 20)
|
|
|
+ ctx.closePath()
|
|
|
+ ctx.fillStyle = g
|
|
|
ctx.fill()
|
|
|
- ctx.strokeStyle = accent
|
|
|
- ctx.globalAlpha = 0.5
|
|
|
- ctx.lineWidth = 1
|
|
|
+ // línea de la onda (definición sutil)
|
|
|
ctx.beginPath()
|
|
|
- ctx.arc(v.x, v.y, 4.4, 0, Math.PI * 2)
|
|
|
- ctx.stroke()
|
|
|
- }
|
|
|
- ctx.globalAlpha = 1
|
|
|
-
|
|
|
- // chips IC
|
|
|
- for (const c of chips) {
|
|
|
- const isGw = c.kind === 'gw'
|
|
|
- roundRectPath(c.x, c.y, c.w, c.h, 3)
|
|
|
- ctx.fillStyle = elevated
|
|
|
- ctx.globalAlpha = 0.7
|
|
|
- ctx.fill()
|
|
|
- ctx.strokeStyle = isGw ? accent : borderStrong
|
|
|
- ctx.globalAlpha = isGw ? 0.55 : 0.3
|
|
|
- ctx.lineWidth = 1
|
|
|
+ ctx.moveTo(-span, base + sample(l, -span, t))
|
|
|
+ for (let x = 0; x <= w + span; x += span) ctx.lineTo(x, base + sample(l, x, t))
|
|
|
+ ctx.strokeStyle = alphaColor(col, l.peak * 0.6)
|
|
|
+ ctx.lineWidth = 1.2
|
|
|
ctx.stroke()
|
|
|
- // pin 1
|
|
|
- ctx.fillStyle = isGw ? accent : borderStrong
|
|
|
- ctx.globalAlpha = isGw ? 0.8 : 0.4
|
|
|
- ctx.beginPath()
|
|
|
- ctx.arc(c.x + 4, c.y + 4, 1.4, 0, Math.PI * 2)
|
|
|
- ctx.fill()
|
|
|
- // pines laterales
|
|
|
- ctx.strokeStyle = borderStrong
|
|
|
- ctx.globalAlpha = 0.35
|
|
|
- ctx.lineWidth = 1
|
|
|
- const pins = Math.max(2, Math.round(c.h / 9))
|
|
|
- for (let i = 0; i < pins; i++) {
|
|
|
- const yp = c.y + ((i + 0.5) / pins) * c.h
|
|
|
- ctx.beginPath(); ctx.moveTo(c.x - 3, yp); ctx.lineTo(c.x, yp); ctx.stroke()
|
|
|
- ctx.beginPath(); ctx.moveTo(c.x + c.w, yp); ctx.lineTo(c.x + c.w + 3, yp); ctx.stroke()
|
|
|
- }
|
|
|
- ctx.globalAlpha = 1
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- function draw(now) {
|
|
|
- const t = now / 1000
|
|
|
- drawStatic()
|
|
|
- // pulsos de señal viajando por las pistas
|
|
|
- const colors = { accent: getCssVar('accent'), tunnel: getCssVar('tunnel'), ok: getCssVar('ok'), info: getCssVar('info'), warn: getCssVar('warn') }
|
|
|
- for (const p of pulses) {
|
|
|
- const tr = traces[p.ti]
|
|
|
- const frac = (p.off + t / p.dur) % 1
|
|
|
- const pt = ptAt(tr, frac * tr.total)
|
|
|
- ctx.save()
|
|
|
- ctx.globalAlpha = 0.85
|
|
|
- ctx.fillStyle = colors[p.color]
|
|
|
- ctx.shadowColor = colors[p.color]
|
|
|
- ctx.shadowBlur = 9
|
|
|
- ctx.beginPath()
|
|
|
- ctx.arc(pt.x, pt.y, 1.9, 0, Math.PI * 2)
|
|
|
- ctx.fill()
|
|
|
- ctx.restore()
|
|
|
- }
|
|
|
- // sonda del cursor (brillo suave)
|
|
|
- if (mx > -1000) {
|
|
|
- const accent = getCssVar('accent')
|
|
|
- const g = ctx.createRadialGradient(mx, my, 0, mx, my, 120)
|
|
|
- g.addColorStop(0, alphaColor(accent, 0.06))
|
|
|
- g.addColorStop(1, alphaColor(accent, 0))
|
|
|
- ctx.fillStyle = g
|
|
|
- ctx.fillRect(mx - 120, my - 120, 240, 240)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -293,19 +124,14 @@ function initBackgroundCanvas() {
|
|
|
canvas.width = Math.round(w * dpr)
|
|
|
canvas.height = Math.round(h * dpr)
|
|
|
ctx.setTransform(dpr, 0, 0, dpr, 0, 0)
|
|
|
- buildLayout()
|
|
|
- if (reduce) drawStatic()
|
|
|
+ buildLayers()
|
|
|
+ if (reduce) render(0)
|
|
|
}
|
|
|
resize()
|
|
|
window.addEventListener('resize', resize)
|
|
|
- document.addEventListener('mousemove', (e) => { tmx = e.clientX; tmy = e.clientY }, { passive: true })
|
|
|
- document.addEventListener('touchmove', (e) => { if (e.touches[0]) { tmx = e.touches[0].clientX; tmy = e.touches[0].clientY } }, { passive: true })
|
|
|
- document.addEventListener('mouseleave', () => { tmx = -1e4; tmy = -1e4 })
|
|
|
if (reduce) return
|
|
|
- const lerp = () => { mx += (tmx - mx) * 0.08; my += (tmy - my) * 0.08 }
|
|
|
function loop(now) {
|
|
|
- lerp()
|
|
|
- draw(now)
|
|
|
+ render(now / 1000)
|
|
|
requestAnimationFrame(loop)
|
|
|
}
|
|
|
requestAnimationFrame(loop)
|