Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 | import type { NumberLineState, TickThresholds, RenderConstant, PrimeTickInfo } from './types' import { DEFAULT_TICK_THRESHOLDS } from './types' import type { CollisionFadeMap } from '../shared/collisionDetection' import { computeTickMarks, numberToScreenX } from './numberLineTicks' import { renderConstantDropLines } from './constants/renderConstants' import { primeColorRgba } from './primes/primeColors' import type { PrimePairArc } from './primes/specialPrimes' import { MERSENNE_PRIMES, ARC_COLORS } from './primes/specialPrimes' import type { InterestingPrime } from './primes/interestingness' import type { SieveTickTransform } from './primes/renderSieveOverlay' import { getTickHeight, getTickLineWidth, getTickAlpha, getTickFontSize, getTickFontWeight, formatTickLabel, LIGHT_COLORS, DARK_COLORS, COLLISION_FADE_MS, SYSTEM_FONT, } from '../shared/tickMath' export interface RenderTarget { value: number emoji: string /** Pre-computed opacity (0-1) from proximity engine */ opacity: number } export interface RenderIndicator { numbers: number[] range?: { from: number; to: number } /** Pre-computed overall alpha (0-1) handling fade-in/hold/fade-out lifecycle */ alpha: number } /** * Render the number line onto a canvas context. * Assumes ctx.scale(dpr, dpr) has already been called. */ export function renderNumberLine( ctx: CanvasRenderingContext2D, state: NumberLineState, cssWidth: number, cssHeight: number, isDark: boolean, thresholds: TickThresholds = DEFAULT_TICK_THRESHOLDS, zoomVelocity = 0, zoomHue = 0, zoomFocalX = 0.5, target?: RenderTarget, collisionFadeMap?: CollisionFadeMap, constants?: RenderConstant[], primeInfos?: Map<number, PrimeTickInfo>, hoveredTick?: number | null, interestingPrimes?: InterestingPrime[], primePairArcs?: PrimePairArc[], highlightedPrimes?: Set<number>, highlightedArcs?: Set<string>, sieveTransforms?: Map<number, SieveTickTransform>, /** 0-1 blend toward uniform tick sizes during sieve (smooth ramp-in) */ sieveUniformity = 0, indicator?: RenderIndicator, /** Multiplier for all label font sizes (0.5–3, default 1) */ labelScale = 1, /** Minimum opacity floor for all labels (0–1, default 0) */ labelMinOpacity = 0 ): boolean { const colors = isDark ? DARK_COLORS : LIGHT_COLORS const centerY = cssHeight / 2 // Clear ctx.clearRect(0, 0, cssWidth, cssHeight) // Zoom velocity background wash — hue and focal point are pre-smoothed by caller if (Math.abs(zoomVelocity) > 0.001) { const intensity = Math.min(Math.abs(zoomVelocity) * 3, 0.35) const sat = 80 const lum = isDark ? 30 : 70 const focalPx = zoomFocalX * cssWidth const gradient = ctx.createRadialGradient(focalPx, centerY, 0, focalPx, centerY, cssWidth * 0.7) gradient.addColorStop(0, `hsla(${zoomHue}, ${sat}%, ${lum}%, ${intensity})`) gradient.addColorStop(1, `hsla(${zoomHue}, ${sat}%, ${lum}%, 0)`) ctx.fillStyle = gradient ctx.fillRect(0, 0, cssWidth, cssHeight) } // Draw horizontal axis line ctx.beginPath() ctx.moveTo(0, centerY) ctx.lineTo(cssWidth, centerY) ctx.strokeStyle = colors.axisLine ctx.lineWidth = 1 ctx.stroke() // Indicator pass: range band + point glows (drawn behind ticks) if (indicator && indicator.alpha > 0) { const a = indicator.alpha const accentHue = 200 // blue accent const accentSat = 90 const accentLumRange = isDark ? 55 : 50 const accentLumPoint = isDark ? 65 : 55 // Range band if (indicator.range) { const fromX = numberToScreenX( indicator.range.from, state.center, state.pixelsPerUnit, cssWidth ) const toX = numberToScreenX(indicator.range.to, state.center, state.pixelsPerUnit, cssWidth) const left = Math.min(fromX, toX) const right = Math.max(fromX, toX) ctx.fillStyle = `hsla(${accentHue}, ${accentSat}%, ${accentLumRange}%, ${a * 0.15})` ctx.fillRect(left, 0, right - left, cssHeight) // Brighter edge lines ctx.strokeStyle = `hsla(${accentHue}, ${accentSat}%, ${accentLumRange}%, ${a * 0.35})` ctx.lineWidth = 1.5 ctx.beginPath() ctx.moveTo(left, 0) ctx.lineTo(left, cssHeight) ctx.moveTo(right, 0) ctx.lineTo(right, cssHeight) ctx.stroke() } // Point glows const pulsePhase = (Date.now() % 2000) / 2000 const pulseScale = 1 + 0.15 * Math.sin(pulsePhase * Math.PI * 2) for (const n of indicator.numbers) { const x = numberToScreenX(n, state.center, state.pixelsPerUnit, cssWidth) if (x < -30 || x > cssWidth + 30) continue const radius = 20 * pulseScale const glow = ctx.createRadialGradient(x, centerY, 0, x, centerY, radius) glow.addColorStop(0, `hsla(${accentHue}, ${accentSat}%, ${accentLumPoint}%, ${a * 0.7})`) glow.addColorStop(0.5, `hsla(${accentHue}, ${accentSat}%, ${accentLumPoint}%, ${a * 0.25})`) glow.addColorStop(1, `hsla(${accentHue}, ${accentSat}%, ${accentLumPoint}%, 0)`) ctx.fillStyle = glow ctx.fillRect(x - radius, centerY - radius, radius * 2, radius * 2) } } // Compute ticks const ticks = computeTickMarks(state, cssWidth, thresholds) // During sieve animation: smoothly blend integer ticks toward uniform // prominence. The normal tick system uses magnitude-based hierarchy (powers // of 10) which hides individual integers at low zoom. The sieve needs every // integer visible so composites can shake/fall and primes remain standing. // sieveUniformity (0-1) controls the blend so the transition is gradual. // Gate on sieveUniformity alone — the transform map may still be empty // during the intro before factor 2's sweep marks any composites. const u = sieveUniformity if (u > 0) { const UNIFORM_PROMINENCE = 0.7 const halfRange = cssWidth / (2 * state.pixelsPerUnit) const minInt = Math.max(1, Math.floor(state.center - halfRange) - 1) const maxInt = Math.ceil(state.center + halfRange) + 1 const existingValues = new Set(ticks.map((t) => t.value)) // Inject missing integer ticks (fade in with uniformity blend) for (let n = minInt; n <= maxInt; n++) { if (!existingValues.has(n)) { ticks.push({ value: n, power: 0, prominence: UNIFORM_PROMINENCE * u, opacity: u }) } } // Blend existing integer ticks toward uniform prominence for (const tick of ticks) { if (Number.isInteger(tick.value) && tick.value >= 1 && existingValues.has(tick.value)) { tick.prominence += (UNIFORM_PROMINENCE - tick.prominence) * u tick.opacity += (1 - tick.opacity) * u } } } // Pre-compute screen positions const ticksWithX = ticks.map((tick) => ({ tick, x: numberToScreenX(tick.value, state.center, state.pixelsPerUnit, cssWidth), })) // Compute per-power label rotation angle. // When labels fit horizontally: angle = 0. As they get more crowded the angle // increases smoothly. At angle θ the horizontal footprint is labelWidth·cos(θ), // so the exact no-overlap angle is acos(spacing / labelWidth). const LABEL_PAD = 6 const MAX_LABEL_ANGLE = Math.PI / 3 // cap at 60° const powerAngle = new Map<number, number>() const powerSpacingPx = new Map<number, number>() for (const { tick } of ticksWithX) { if (!powerSpacingPx.has(tick.power)) { const spacing = 10 ** tick.power powerSpacingPx.set(tick.power, spacing * state.pixelsPerUnit) } } // Measure a representative label for each power to compute the needed angle const measuredPowers = new Set<number>() for (const { tick } of ticksWithX) { if (measuredPowers.has(tick.power)) continue if (tick.opacity <= 0) continue measuredPowers.add(tick.power) const fontSize = getTickFontSize(tick.prominence) const fontWeight = getTickFontWeight(tick.prominence) ctx.font = `${fontWeight} ${fontSize}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif` const label = formatTickLabel(tick.value, tick.power) const labelWidth = ctx.measureText(label).width const spacingPx = powerSpacingPx.get(tick.power) ?? Infinity // ratio < 1 means labels overlap horizontally const ratio = Math.max(0, spacingPx - LABEL_PAD) / labelWidth if (ratio >= 1) { powerAngle.set(tick.power, 0) } else { // acos(ratio) gives the exact angle where labels just fit powerAngle.set(tick.power, Math.min(Math.acos(ratio), MAX_LABEL_ANGLE)) } } // Pre-compute label info for cross-power collision detection. // Each label occupies a horizontal extent on the x-axis; when a lower-prominence // label overlaps a higher-prominence one, the lower-prominence label is hidden. interface LabelInfo { tick: (typeof ticksWithX)[number]['tick'] x: number label: string fontSize: number fontWeight: number labelWidth: number angle: number height: number /** Horizontal extent: [xMin, xMax] on the canvas */ xMin: number xMax: number } const labelInfos: LabelInfo[] = [] for (const { tick, x } of ticksWithX) { if (x < -50 || x > cssWidth + 50) continue if (tick.opacity <= 0) continue const label = formatTickLabel(tick.value, tick.power) const fontSize = getTickFontSize(tick.prominence) const fontWeight = getTickFontWeight(tick.prominence) ctx.font = `${fontWeight} ${fontSize}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif` const labelWidth = ctx.measureText(label).width const angle = powerAngle.get(tick.power) ?? 0 const height = getTickHeight(tick.prominence, cssHeight) // Compute horizontal footprint of the (possibly rotated) label. // The label is drawn at (x, labelY) then rotated by angle. // Its horizontal extent is approximately labelWidth·cos(angle) + fontSize·sin(angle). const t = MAX_LABEL_ANGLE > 0 ? Math.min(angle / MAX_LABEL_ANGLE, 1) : 0 const xOffset = (-labelWidth / 2) * (1 - t) const hFootprint = labelWidth * Math.cos(angle) + fontSize * Math.sin(angle) const xMin = x + xOffset * Math.cos(angle) const xMax = xMin + hFootprint labelInfos.push({ tick, x, label, fontSize, fontWeight, labelWidth, angle, height, xMin, xMax }) } // Sort by prominence descending so higher-prominence labels take priority labelInfos.sort((a, b) => b.tick.prominence - a.tick.prominence) // Mark which labels survive collision detection const labelVisible = new Set<LabelInfo>() const occupiedExtents: { xMin: number; xMax: number }[] = [] for (const info of labelInfos) { const pad = LABEL_PAD / 2 let overlaps = false for (const occ of occupiedExtents) { if (info.xMin - pad < occ.xMax && info.xMax + pad > occ.xMin) { overlaps = true break } } if (!overlaps) { labelVisible.add(info) occupiedExtents.push({ xMin: info.xMin, xMax: info.xMax }) } } // Pass 1: tick lines let maxTickHeight = 0 for (const { tick, x } of ticksWithX) { if (x < -50 || x > cssWidth + 50) continue // Apply sieve transforms: skip fully hidden ticks const sxf = sieveTransforms?.get(tick.value) if (sxf && sxf.opacity <= 0.01) continue let height = getTickHeight(tick.prominence, cssHeight) if (height > maxTickHeight) maxTickHeight = height let lineWidth = getTickLineWidth(tick.prominence) const tickAlpha = getTickAlpha(tick.prominence) const primeInfo = primeInfos?.get(tick.value) const isHovered = hoveredTick != null && tick.value === hoveredTick // Prime ticks: slightly taller + thicker if (primeInfo?.isPrime) { height *= 1.15 lineWidth += 0.5 } // Apply sieve transform (shake, fall, rotation) const hasXf = sxf && (sxf.offsetX !== 0 || sxf.offsetY !== 0 || sxf.rotation !== 0) if (hasXf) { ctx.save() ctx.translate(x + sxf.offsetX, sxf.offsetY) ctx.translate(0, centerY) ctx.rotate(sxf.rotation) ctx.translate(0, -centerY) } ctx.globalAlpha = tick.opacity * (sxf?.opacity ?? 1) ctx.beginPath() if (hasXf) { // Already translated to (x + offsetX, 0), draw relative to 0 ctx.moveTo(0, centerY - height) ctx.lineTo(0, centerY + height) } else { ctx.moveTo(x, centerY - height) ctx.lineTo(x, centerY + height) } if (primeInfo && primeInfo.classification !== 'one') { // Color by smallest prime factor const alpha = isHovered ? Math.min(1, tickAlpha + 0.3) : tickAlpha ctx.strokeStyle = primeColorRgba(primeInfo.smallestPrimeFactor, alpha, isDark) } else { ctx.strokeStyle = `rgba(${colors.tickRgb}, ${tickAlpha})` } ctx.lineWidth = lineWidth ctx.stroke() // Hover highlight: subtle glow ring if (isHovered && primeInfo && primeInfo.classification !== 'one') { const savedAlpha = ctx.globalAlpha ctx.globalAlpha = 0.25 * tick.opacity * (sxf?.opacity ?? 1) ctx.strokeStyle = primeColorRgba(primeInfo.smallestPrimeFactor, 1, isDark) ctx.lineWidth = lineWidth + 3 ctx.beginPath() if (hasXf) { ctx.moveTo(0, centerY - height) ctx.lineTo(0, centerY + height) } else { ctx.moveTo(x, centerY - height) ctx.lineTo(x, centerY + height) } ctx.stroke() ctx.globalAlpha = savedAlpha } if (hasXf) ctx.restore() ctx.globalAlpha = 1 } // Pass 2: labels with smooth collision fade. // All labels are rendered (not just visible ones) so that collision-hidden // labels can fade out over COLLISION_FADE_MS instead of disappearing instantly. const now = performance.now() let animating = false const seenValues = new Set<number>() for (const info of labelInfos) { const { tick, x, label, fontSize, fontWeight, labelWidth, angle, height } = info // Apply sieve transforms: skip fully hidden labels const sxf = sieveTransforms?.get(tick.value) if (sxf && sxf.opacity <= 0.01) continue // During sieve: skip collision detection entirely. Composites are already // hidden by the opacity<=0.01 check above; only primes remain, and they // should all show labels regardless of overlap at low zoom. const sieveActive = u > 0 const hasSieveXf = sxf && (sxf.offsetX !== 0 || sxf.offsetY !== 0 || sxf.rotation !== 0) const isVisible = sieveActive || hasSieveXf || labelVisible.has(info) seenValues.add(tick.value) // Compute collision opacity (1 = fully visible, 0 = collision-hidden) let collisionOpacity = isVisible ? 1 : 0 if (collisionFadeMap && !sieveActive && !hasSieveXf) { let entry = collisionFadeMap.get(tick.value) if (!entry) { // First time seeing this label — no fade, just snap to current state entry = { visible: isVisible, startTime: now, startOpacity: isVisible ? 1 : 0 } collisionFadeMap.set(tick.value, entry) } else if (entry.visible !== isVisible) { // Visibility changed — start transition from current animated position const elapsed = now - entry.startTime const t = Math.min(1, elapsed / COLLISION_FADE_MS) const prevTarget = entry.visible ? 1 : 0 const currentOpacity = entry.startOpacity + (prevTarget - entry.startOpacity) * t entry.visible = isVisible entry.startTime = now entry.startOpacity = currentOpacity } const elapsed = now - entry.startTime const t = Math.min(1, elapsed / COLLISION_FADE_MS) const target = entry.visible ? 1 : 0 collisionOpacity = entry.startOpacity + (target - entry.startOpacity) * t if (t < 1) animating = true } // Skip fully hidden labels if (collisionOpacity <= 0.01) continue const labelAlpha = Math.max(getTickAlpha(tick.prominence), labelMinOpacity) const scaledFontSize = fontSize * labelScale ctx.font = `${fontWeight} ${scaledFontSize}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif` ctx.globalAlpha = tick.opacity * collisionOpacity * (sxf?.opacity ?? 1) const labelPrimeInfo = primeInfos?.get(tick.value) if (labelPrimeInfo && labelPrimeInfo.classification !== 'one') { ctx.fillStyle = primeColorRgba(labelPrimeInfo.smallestPrimeFactor, labelAlpha, isDark) } else { ctx.fillStyle = `rgba(${colors.labelRgb}, ${labelAlpha})` } const labelY = centerY + height + 4 // t: 0 = fully horizontal/centered, 1 = fully rotated/left-aligned const tAngle = MAX_LABEL_ANGLE > 0 ? Math.min(angle / MAX_LABEL_ANGLE, 1) : 0 const xOffset = (-labelWidth / 2) * (1 - tAngle) ctx.save() if (hasSieveXf) { // Apply sieve transform: translate + rotate around the label's position ctx.translate(x + sxf.offsetX, labelY + sxf.offsetY) ctx.rotate(sxf.rotation + angle) } else { ctx.translate(x, labelY) ctx.rotate(angle) } ctx.textAlign = 'left' ctx.textBaseline = 'top' ctx.fillText(label, xOffset, 0) ctx.restore() ctx.globalAlpha = 1 } // Clean up stale entries no longer in the viewport if (collisionFadeMap) { for (const key of collisionFadeMap.keys()) { if (!seenValues.has(key)) { collisionFadeMap.delete(key) } } } // Pass 2.25: prime markers // Two sources of prime dots: // (a) Tick-based dots (above prime ticks) — visible when zoomed in enough for integer ticks // (b) Axis-level dots from visiblePrimes — visible at any zoom level, independent of ticks if (primeInfos) { for (const { tick, x } of ticksWithX) { if (x < -50 || x > cssWidth + 50) continue const pi = primeInfos.get(tick.value) if (!pi?.isPrime) continue const height = getTickHeight(tick.prominence, cssHeight) * 1.15 const dotRadius = 2 + tick.prominence * 2 const dotY = centerY - height - 4 ctx.globalAlpha = tick.opacity ctx.beginPath() ctx.arc(x, dotY, dotRadius, 0, Math.PI * 2) ctx.fillStyle = primeColorRgba(pi.value, 0.85, isDark) ctx.fill() // Mersenne prime halo if (MERSENNE_PRIMES.has(pi.value)) { ctx.beginPath() ctx.arc(x, dotY, dotRadius + 3, 0, Math.PI * 2) ctx.strokeStyle = isDark ? 'rgba(255, 158, 238, 0.6)' : 'rgba(160, 48, 142, 0.5)' ctx.lineWidth = 1.5 ctx.stroke() } ctx.globalAlpha = 1 } } // Axis-level prime dots (visible when zoomed out) — score-based sizing if (interestingPrimes && interestingPrimes.length > 0) { const count = interestingPrimes.length const baseAlpha = count < 50 ? 0.8 : count < 200 ? 0.65 : count < 800 ? 0.5 : 0.35 // Offset dots slightly above axis so they don't get hidden by the axis line const dotY = centerY - 1 for (const ip of interestingPrimes) { const x = numberToScreenX(ip.value, state.center, state.pixelsPerUnit, cssWidth) if (x < -5 || x > cssWidth + 5) continue // Skip if this prime already has a visible tick-based dot (avoid double-drawing) const tickInfo = primeInfos?.get(ip.value) if (tickInfo) continue // Score-based dot radius: clamp(2 + score/20, 1.5, 6) const dotRadius = Math.max(1.5, Math.min(6, 2 + ip.score / 20)) // Higher-scoring primes are more opaque const alpha = Math.min(baseAlpha + ip.score / 200, 0.95) ctx.globalAlpha = alpha ctx.beginPath() ctx.arc(x, dotY, dotRadius, 0, Math.PI * 2) ctx.fillStyle = primeColorRgba(ip.value, 1, isDark) ctx.fill() // Mersenne prime halo (axis-level) if (MERSENNE_PRIMES.has(ip.value)) { ctx.globalAlpha = Math.min(alpha + 0.2, 0.9) ctx.beginPath() ctx.arc(x, dotY, dotRadius + 2.5, 0, Math.PI * 2) ctx.strokeStyle = isDark ? 'rgba(255, 158, 238, 0.7)' : 'rgba(160, 48, 142, 0.6)' ctx.lineWidth = 1.5 ctx.stroke() } } ctx.globalAlpha = 1 } // Pass 2.3: prime pair arcs (twin / cousin / sexy) — for hovered or highlighted primes const hasExplicitArcs = highlightedArcs && highlightedArcs.size > 0 const showArcs = hoveredTick != null || (highlightedPrimes && highlightedPrimes.size > 0) || hasExplicitArcs if (primePairArcs && primePairArcs.length > 0 && showArcs) { const arcOrder: Array<'sexy' | 'cousin' | 'twin'> = ['sexy', 'cousin', 'twin'] // Pulsing phase for tour arc glow const arcPulsePhase = (Date.now() % 2000) / 2000 const arcPulseAlpha = 0.2 + 0.15 * Math.sin(arcPulsePhase * Math.PI * 2) for (const arcType of arcOrder) { const colorTemplate = isDark ? ARC_COLORS[arcType].dark : ARC_COLORS[arcType].light const baseAlpha = arcType === 'twin' ? 0.7 : arcType === 'cousin' ? 0.6 : 0.5 const baseLineWidth = arcType === 'twin' ? 1.5 : 1.2 for (const arc of primePairArcs) { if (arc.type !== arcType) continue const arcKey = `${arc.p1}-${arc.p2}` const matchesHover = arc.p1 === hoveredTick || arc.p2 === hoveredTick let matchesHighlight = false if (hasExplicitArcs) { // Explicit mode: only show arcs in the explicit set matchesHighlight = highlightedArcs!.has(arcKey) } else if (highlightedPrimes && highlightedPrimes.size > 0) { // Legacy mode: any arc touching a highlighted prime matchesHighlight = highlightedPrimes.has(arc.p1) || highlightedPrimes.has(arc.p2) } if (!matchesHover && !matchesHighlight) continue const x1 = numberToScreenX(arc.p1, state.center, state.pixelsPerUnit, cssWidth) const x2 = numberToScreenX(arc.p2, state.center, state.pixelsPerUnit, cssWidth) if (x2 < -10 || x1 > cssWidth + 10) continue const screenDist = x2 - x1 if (screenDist < 3) continue const midX = (x1 + x2) / 2 const arcDepth = Math.min(16, Math.max(3, screenDist * 0.3)) const isTourArc = hasExplicitArcs && highlightedArcs!.has(arcKey) if (isTourArc) { // Tour arc glow pass: wider, pulsing, lower alpha ctx.save() ctx.strokeStyle = colorTemplate.replace('A', String(arcPulseAlpha)) ctx.lineWidth = baseLineWidth + 4 ctx.beginPath() ctx.moveTo(x1, centerY + 1) ctx.quadraticCurveTo(midX, centerY + 1 + arcDepth, x2, centerY + 1) ctx.stroke() ctx.restore() // Main arc: boosted alpha + thickness ctx.strokeStyle = colorTemplate.replace('A', String(Math.min(1, baseAlpha + 0.2))) ctx.lineWidth = baseLineWidth + 1 } else { ctx.strokeStyle = colorTemplate.replace('A', String(baseAlpha)) ctx.lineWidth = baseLineWidth } ctx.beginPath() ctx.moveTo(x1, centerY + 1) ctx.quadraticCurveTo(midX, centerY + 1 + arcDepth, x2, centerY + 1) ctx.stroke() } } ctx.globalAlpha = 1 } // Pass 2.5: mathematical constants if (constants && constants.length > 0) { renderConstantDropLines(ctx, constants, centerY, isDark, maxTickHeight) } // Pass 3: target emoji (Find the Number game) if (target && target.opacity > 0) { const tx = numberToScreenX(target.value, state.center, state.pixelsPerUnit, cssWidth) // Scale emoji size with opacity: 24px at low opacity, 40px at full const emojiSize = 24 + 16 * target.opacity // Pulsing glow when nearly found if (target.opacity > 0.8) { const pulsePhase = (Date.now() % 1500) / 1500 const pulseAlpha = 0.15 + 0.1 * Math.sin(pulsePhase * Math.PI * 2) const glowRadius = emojiSize * 1.2 const glow = ctx.createRadialGradient(tx, centerY, 0, tx, centerY, glowRadius) glow.addColorStop(0, `hsla(45, 100%, 60%, ${pulseAlpha * target.opacity})`) glow.addColorStop(1, `hsla(45, 100%, 60%, 0)`) ctx.globalAlpha = 1 ctx.fillStyle = glow ctx.fillRect(tx - glowRadius, centerY - glowRadius, glowRadius * 2, glowRadius * 2) } ctx.globalAlpha = target.opacity ctx.font = `${emojiSize}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Emoji, sans-serif` ctx.textAlign = 'center' ctx.textBaseline = 'middle' ctx.fillStyle = isDark ? '#fff' : '#000' ctx.fillText(target.emoji, tx, centerY) ctx.globalAlpha = 1 } return animating } |