Three.js Scroll Circuit Board Trace — Self-Routing PCB Effect

Three.js Scroll Circuit Board Trace · Scroll · Plain HTML, CSS & JS · Live preview

What's included

Features

Manhattan-style route generator produces plausible axis-aligned circuit paths, computed once
Traces "draw" themselves via THREE.BufferGeometry.setDrawRange — no per-frame geometry rebuilding
Sequential per-trace ordering staggers routing so traces visibly complete one after another
Duplicate additive-blended halo lines fake a neon PCB glow with zero postprocessing pipeline
Chip boxes scale in based on the average completion of their incoming traces
Cyan-to-green emissive palette against a dark board reads as a cohesive cyberpunk PCB
Camera makes a slow orbiting descent as routing progresses for a dynamic reveal angle
Fully reversible and pinned — scrolling up unroutes the board with zero extra code

About this UI Snippet

How to Build a Scroll-Driven Self-Drawing Circuit Board With Three.js

Screenshot of the Three.js Scroll Circuit Board Trace snippet rendered live

The Three.js Scroll Circuit Board Trace snippet generates a set of Manhattan-routed circuit paths once, then reveals each one segment by segment — like a PCB autorouter working in real time — as the visitor scrolls through a pinned stage, converging on glowing chip boxes.

Manhattan routing without a real autorouter

routeTrace() walks from a random edge point toward a chip target in axis-aligned (horizontal-then-vertical) steps, picking whichever axis has more distance remaining at each step — a simplified stand-in for how a real PCB autorouter lays traces in 90-degree turns rather than diagonals. The result is a point list per trace that already looks like plausible circuit routing, computed once and never touched again.

Drawing a line progressively with drawRange, not tweened geometry

Rather than animating vertex positions, each trace's full point list is uploaded once into a THREE.BufferGeometry, and "drawing" it is simply calling geometry.setDrawRange(0, count) with a growing count — WebGL only renders the first count vertices of the line strip. This is far cheaper than rebuilding geometry per frame and trivially reversible: shrinking count erases the trace from the end backward exactly as it was drawn.

Staggering traces so they route one after another

Every trace is assigned a sequential order at generation time, and its visible fraction is only nonzero within its own slice of the overall scroll range (order / totalTraces to a bit past that). That staggering is what makes the board look like traces are being routed one at a time rather than every trace inching forward simultaneously — the same staggered-reveal idea used by branch growth in coral reef grow, applied here to line segments instead of cylinders.

A cheap glow without a bloom postprocessing pass

Each trace is drawn twice from the same geometry: once as a crisp, fully opaque LineBasicMaterial line, and once as a wider-reading, lower-opacity AdditiveBlending "halo" copy underneath. Because both share the same drawRange-driven geometry, the halo reveals in perfect sync with the trace, faking a neon PCB glow with zero postprocessing setup.

Chip boxes that power on as their traces complete

Each chip's visible scale is the average completion fraction of every trace routed to it, so a chip box grows into place only once its incoming traces have mostly arrived — reinforcing the feeling that the chip is being "powered up" by the circuit connecting to it, rather than appearing on an unrelated timer.

Build with AI

Build, Understand, Optimize, and Extend It With AI

You do not need to reverse-engineer how a circuit board routes itself on scroll without a real autorouter or bloom pass. Paste this snippet's HTML, CSS, and JS into an AI assistant like Claude and ask it to explain why setDrawRange is used instead of animating vertex positions, or how the per-trace order index creates a staggered one-after-another routing sequence. The same assistant can help you extend it — ask it to add via-hole dots at each turn point, make traces pulse briefly after completing, or vary trace width by giving them THREE.TubeGeometry instead of plain lines. It can also help optimize further, for instance batching all traces into one BufferGeometry with per-trace draw ranges via multiple draw calls. Treat the code as a conversation starter, not a finished artifact.

Prompt to recreate it

Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:

text
Build a "scroll-scrubbed self-routing circuit board" effect in plain HTML, CSS, and JavaScript using Three.js, GSAP, and GSAP's ScrollTrigger plugin, all loaded from a CDN (no bundler, no build step).

Requirements:
- A pinned section containing a full-size canvas, with a WebGLRenderer and PerspectiveCamera sized to it and updated on window resize including aspect ratio, viewing a dark plane representing a PCB.
- Write a function that generates a Manhattan-style (axis-aligned, 90-degree-turn) route as a list of points from a random point on the board's edge to one of a few fixed "chip" target positions, by repeatedly stepping along whichever of the horizontal/vertical axis has more remaining distance to the target.
- Generate roughly 15-20 such traces, each converging on one of 2-3 chip positions, and upload each trace's point list once into its own THREE.BufferGeometry rendered as a THREE.Line, plus a second, wider-reading, additively-blended low-opacity "halo" line sharing the same geometry to fake a neon glow with no postprocessing.
- Assign each trace a sequential order index, and reveal it progressively via geometry.setDrawRange(0, count), where count grows from 0 to the trace's full vertex count only within that trace's own slice of the overall scroll progress range, so traces visibly complete one after another rather than all advancing together.
- Add a small box mesh at each chip position that scales in based on the average completion fraction of its incoming traces, so chips visually power on as their traces arrive.
- Register a GSAP tween on a ScrollTrigger targeting the pinned section, with pin: true, start at top top, a numeric scrub, and a multi-hundred-percent end, animating a single plain progress value from 0 to 1 with linear easing that drives all of the above.
- Confirm scrolling back up erases every trace from its endpoint backward and shrinks the chips back down, exactly in reverse, since drawRange and chip scale are both pure functions of the current scrubbed progress value.

Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.

Source Code

<section class="pcb-stage" id="pcbStage">
  <div class="pcb-intro-overlay"><p>Scroll ↓ to route a circuit board trace by trace</p></div>
  <canvas id="pcbCanvas"></canvas>
  <div class="pcb-hud"><span id="pcbPct">0</span>% routed</div>
</section>
<section class="pcb-bottom"><p>Fully routed. All traces reach their chips.</p></section>

Step by step

How to Use

  1. 1
    Load all three CDN scriptsAdd three.min.js, gsap.min.js, and ScrollTrigger.min.js from the CDN panel, in that order.
  2. 2
    Paste HTML, CSS, and JSA bare dark PCB appears inside a pinned 3D stage with a live "% routed" read-out.
  3. 3
    Scroll downEighteen traces route themselves in sequence toward three chip boxes, which power on as their traces arrive.
  4. 4
    Scroll back upTraces erase from their endpoint backward and chips power back down, exactly in reverse.
  5. 5
    Retune the layoutChange CHIPS for different chip positions, or TRACES_PER_CHIP for a denser or sparser board.
  6. 6
    Adjust the pacingChange the ScrollTrigger end value (+=420%) for a slower or faster routing sequence.

Real-world uses

Common Use Cases

Hardware and electronics brand sites
Open a chipmaker, PCB manufacturer, or hardware-startup homepage with a literal circuit-routing hero animation.
Developer tool and SaaS landing pages
A self-assembling circuit motif reads as "infrastructure coming online," fitting for dev-tools and backend platforms.
Tech conference and hackathon sites
A cyberpunk-toned routing animation suits hardware hackathons and tech-conference hero sections.
Cyberpunk or sci-fi game landing pages
Pair with hologram scan for a layered tech-interface scroll story.
Teaching BufferGeometry drawRange
A compact real-world example of progressive line reveal via drawRange instead of animating vertex positions.
Scroll-story chapter breaks
Use the routing sequence as a mid-page transition, similar to how galaxy formation bridges sections.

Got questions?

Frequently Asked Questions

setDrawRange tells WebGL to render only the first N vertices of an already-uploaded line strip, so "drawing" a trace is a single integer update instead of rewriting a Float32Array every frame. It is both cheaper and trivially reversible — decreasing the count erases the trace from its most recently drawn end.

From a starting point, routeTrace() repeatedly compares the remaining horizontal and vertical distance to the target and steps a random amount along whichever axis has more distance left, appending each turn point to a list. This produces the right-angle, segment-by-segment paths characteristic of real PCB traces without implementing a full autorouter.

Every trace is given a sequential order index when it is generated. Its own visible fraction only becomes nonzero once scroll progress passes order / totalTraces, and reaches full draw a little further on. Because each trace owns a distinct slice of the overall progress range, traces visibly complete in generation order rather than all advancing together.

Each trace is rendered twice from the exact same drawRange-driven geometry: a crisp opaque line plus a lower-opacity, additively blended copy. The additive halo brightens where it overlaps the board and the crisp line beneath it, reading as a soft glow without any extra render passes or full-screen shader.

Yes. Click JSX for a React component, Vue for a Vue 3 SFC, Angular for a standalone component, or Tailwind for a React + Tailwind version. Generate traces and chips inside a mount effect keyed to a canvas ref, and on unmount kill the ScrollTrigger instance, dispose all geometries and materials, and call renderer.dispose().