← Back to the blog
Blog

How a Low-Poly Background Is Actually Generated: Points, Delaunay and a Gradient

· 8 min read · by Roberto Iacono

People are often surprised by how little code it takes to generate a low-poly background. There’s no 3D engine and no machine learning involved: just a few dozen lines that scatter points, connect them into triangles and color each one. This post walks through the exact algorithm behind the TriangleBG generator, step by step, with the numbers that actually matter. If you want to build your own, or just understand what the sliders do, this is for you.

Step 1: Start with a grid, then break it

The simplest way to cover a rectangle with points is a regular grid. If the image is 1200×800 pixels and the cell size is 100, you get a grid of points every 100 pixels: 13 columns by 9 rows.

A perfect grid gives you perfectly regular triangles, which looks like graph paper, not low poly. So each point gets pushed a random amount in both directions. The maximum push is the cell size multiplied by a value called variance:

offsetX = (random() - 0.5) * cellSize * variance
offsetY = (random() - 0.5) * cellSize * variance

At variance 0, nothing moves. At variance 1, a point can move up to half a cell in either direction, which is about as far as you can go before triangles start looking like slivers. Most good-looking results live between 0.3 and 0.6.

One detail that is easy to miss: the grid has to extend beyond the edges of the image. If points stop exactly at the border, the outer triangles get clipped into straight, regular edges and the image looks like it has a frame. The generator adds two cells of padding on every side and lets those triangles fall off the canvas.

Step 2: Make the randomness repeatable

Math.random()gives a different result every time, which is a problem: if you find a layout you like, refresh the page and it’s gone. The fix is a seededrandom number generator. Give it the same seed and it produces exactly the same sequence of “random” numbers.

TriangleBG uses the seedrandom library for this. That’s why the editor has a seed field: the seed plus the settings fully describe a background. Same inputs, same image, on any machine.

Step 3: Connect the dots with Delaunay triangulation

Now you have a cloud of slightly messy points and need to connect them into triangles. There are many ways to do that, and most of them look bad: long, thin triangles crossing the whole image.

Delaunay triangulation is the standard answer. It connects the points so that no point lies inside the circle passing through the three corners of any triangle. In practice, that rule maximizes the smallest angle across all triangles. Fewer slivers, more triangles that look roughly equilateral, which is exactly the look you want.

You don’t need to implement it yourself. The d3-delaunay package does it in a single call and is fast enough to rerun on every slider change:

import { Delaunay } from "d3-delaunay";

const delaunay = Delaunay.from(points);
const t = delaunay.triangles; // flat array: [a, b, c, a, b, c, ...]

The result is a flat array of point indices, three per triangle. For a 1920×1080 image with a cell size of 100, that’s roughly 400 visible triangles, plus some more in the padding area.

Step 4: Color each triangle from a gradient

Each triangle gets a single flat color, and that is what makes the result look low poly instead of like a smooth gradient. To pick the color, you take the triangle’s center (the average of its three corners) and ask: how far along the gradient is this point?

For a left-to-right gradient that’s simply centerX / width, a number between 0 and 1. For a diagonal it’s the average of the horizontal and vertical positions. That number is then mapped onto a three-color palette: the first half blends from color one to color two, the second half from color two to color three.

A small trick makes the result look better: instead of using the position directly, it goes through an easing curve (0.5 - cos(πt) / 2) that spends more of the image on the two outer colors and moves through the middle color faster. Without it, the middle color tends to dominate and the image looks muddy.

Step 5: Add a bit of noise

If every triangle followed the gradient exactly, neighbouring triangles would have almost the same color and the facets would disappear. So each triangle gets a small random brightness shift. The pattern intensity slider controls how big that shift is. Low values give a subtle texture that works behind text; high values give the crystalline, high-contrast look.

Step 6: Draw without gaps

The last problem is surprisingly annoying. When you fill two triangles that share an edge on a canvas, anti-aliasing often leaves a faint light line between them. Across hundreds of triangles that becomes a visible wireframe.

The fix is to stroke each triangle with a 1px line in its own fill color before filling it. The stroke covers the seam, and since it’s the same color, you don’t see it. In the SVG export the same idea applies: every <polygon> gets a matching stroke.

Putting it together

That’s the whole pipeline:

  1. Lay out a padded grid of points spaced by the cell size.
  2. Jitter each point using a seeded random generator.
  3. Triangulate the points with Delaunay.
  4. Color each triangle by where its center falls in the gradient.
  5. Add a little random noise per triangle.
  6. Fill and stroke each triangle in the same color.

Every slider in the editor maps directly to one of these steps, which is why small changes can make such a big visual difference. If you want to see it in action, open the editorand move the variance slider from 0 to 1 slowly. You’ll see the grid break apart into triangles in real time. And if you’re curious where the look itself came from, I wrote about that in what low-poly design actually is.

Make your own low-poly background

Free online editor, no signup. Export PNG or SVG.

Open the editor