Visualizations
139 / 500

139 · Generative art

Pen Plotter

A SCARA plotter arm inks hatched, hidden-line drawings along a 2-opt optimized route.

Three generative compositions are built as vector strokes with hidden lines removed: an isometric city whose faces are hatched by how much light they catch, every stroke clipped exactly against the silhouettes of the boxes in front; shaded spheres hatched along their own latitude circles, kept only where an ordered dither says the surface is dark enough; and ridgelines drawn with a floating horizon, with a sun behind them all. Before plotting, each pen's strokes are routed to cut pen-up travel: file order first, then nearest neighbor (flipping strokes as needed), then 2-opt, which reverses runs of strokes while that shortens the trip, running a few milliseconds per frame. A two-link SCARA arm, solved with inverse kinematics, then swaps pens from the rack and plots layer by layer, pooling a little ink where the pen lands and fading as each pen runs dry.

Try it. Choose Blocks, Orbs or Ridges (or 1 to 3, N for a new seed), drag the speed slider or use the arrow keys, show or hide the dashed pen-up moves (T), and switch between the optimized route and file order (O) to watch the wasted travel come back. Click the paper to replot.

  • Hidden-line removal
  • Floating horizon
  • Nearest neighbor and 2-opt routing
  • SCARA inverse kinematics
  • Hatching by ordered dither

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build a pen plotter simulator with JavaScript and the HTML canvas element: generate a line drawing, plan the pen's route, and animate a pen drawing it. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Make a canvas that fills the window and stays sharp on high-DPI screens (scale by devicePixelRatio). Draw a cream sheet of paper on a dark background.
- Generate a drawing as a list of strokes, each an array of points: about 60 ridgelines across the page, each a row of points whose height comes from a small noise function you write yourself.
- Remove hidden lines with a floating horizon: draw the nearest ridge first and keep an array with the highest point drawn so far in each column. A point of a later ridge is kept only if it is above that, and a ridge splits into separate strokes where it disappears.
- Animate a pen: it travels to the start of the next stroke with the pen up, then draws along it at a steady speed onto an offscreen canvas that is never cleared. Show the pen as a small circle.

Once that works, make it beautiful:
- Plan the route to cut pen-up travel: chain strokes by nearest neighbor (allowing each stroke to be drawn backward), then improve with 2-opt, reversing a run of strokes whenever that shortens the trip. Show the total pen-up distance before and after.
- Draw the pen-up moves as faint dashed red lines, and add a toggle that plots in the original order so you can see the difference.
- Use two or three pen colors plotted one after another, with a little dot of ink where the pen lands.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as an isometric city with hatched faces and exact hidden-line clipping, a two-link robot arm driven by inverse kinematics, or exporting the plan as SVG for a real plotter.
PreviousOceanRolling waves at sunset, built from layered Gerstner waves. NextEcholocationA bat hunts moths in a black cave that exists only as the echoes of its calls.

Related visualizations

  • Plotter LandscapeGenerative art A mountain range inked stroke by stroke, with exact floating-horizon hidden lines.
  • One Line PortraitType and image Thousands of stipple dots become one unbroken pen line, untangled by 2-opt.
  • HarmonographGenerative art A Victorian pendulum machine inks decaying roses and stars onto cream paper.
  • Parametric TypeType and image A Metafont-style alphabet drawn by a parametric pen, morphing through ten styles.
  • Paper MarblingGenerative art Ink drops, combs and styluses on a size bath, then a print pulled onto paper.
  • Engraving Renderer3D A moving 3D still life printed as a copperplate engraving, line by swelling line.
  • Ink Landscape ScrollGenerative art An endless ink handscroll of misty peaks, pines, pavilions and boats, unrolling.
  • Painterly RenderingGenerative art A harbor at dusk repainted coarse to fine in thousands of curved, bristly strokes.
  • KaleidoscopeGenerative art Draw once, and twelve mirrored strokes bloom into a mandala.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs