explaingit

fogleman/primitive

13,138GoAudience · generalComplexity · 2/5Setup · moderate

TLDR

Primitive recreates any photograph using geometric shapes like triangles, rectangles, and ellipses, producing abstract stylized art you can export as PNG, SVG vector graphic, or animated GIF.

Mindmap

mindmap
  root((repo))
    What It Does
      Photo to shapes
      Abstract art output
      Animated GIF option
      SVG vector output
    Shape Types
      Triangles
      Rectangles
      Ellipses
      Mixed mode
    How It Works
      Random shape trial
      Visual diff scoring
      Iterative improvement
      Per-shape refinement
    Usage
      Command line tool
      macOS GUI app
      Open source Go code
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Turn a photograph into a minimalist geometric art poster to print or share on social media.

USE CASE 2

Generate an animated GIF that shows a photo being reconstructed shape by shape for a satisfying visual effect.

USE CASE 3

Create scalable SVG artwork from photos that can be resized to any dimension without quality loss.

USE CASE 4

Produce a geometric wallpaper or avatar from a portrait photo using a specific shape type and color palette.

Tech stack

GoImageMagick

Getting it running

Difficulty · moderate Time to first run · 30min

GIF output requires ImageMagick installed separately, use small input images around 256x256 pixels for fast results.

In plain English

Primitive is a program that recreates a photograph using simple geometric shapes: triangles, rectangles, ellipses, circles, and similar forms. You give it an image file, tell it how many shapes to use, and it builds up an approximation of that image one shape at a time. The result looks like an abstract, stylized version of the original photo. The algorithm works by trying random shapes and measuring how much each one reduces the visual difference between the current drawing and the target photo. It keeps improving each shape through small random adjustments, keeping changes that make it closer and discarding ones that make it worse. This is repeated for every shape added. With around 50 shapes the result is recognizable but highly abstract. With 200 shapes it is much closer to the original while still looking painted or geometric. You run it from the command line. After installing Go and fetching the package, the basic command takes an input image, an output filename, and the number of shapes. You can also choose the shape type: triangles by default, but rectangles, ellipses, circles, rotated variants, or a mix are all options. The output can be a PNG or JPG file, an SVG vector graphic, or an animated GIF that shows each shape being added in sequence. For the GIF output, ImageMagick needs to be installed separately. The README recommends using small input images, around 256 by 256 pixels, because smaller files make the algorithm faster without affecting quality much since fine detail gets averaged away anyway. There is also a native macOS application available at primitive.lol if you prefer a graphical interface over the command line. The project is written in Go and the code is open source.

Copy-paste prompts

Prompt 1
Give me the command to convert a photo called portrait.jpg into a primitive geometric image using 200 triangles, saved as output.png.
Prompt 2
Show me how to generate an animated GIF with Primitive that shows my photo.jpg being built up from 100 rectangles one by one.
Prompt 3
How do I use Primitive to create an SVG vector version of an image using ellipses instead of triangles?
Prompt 4
What input image size does Primitive recommend for fast processing, and how do I resize my photo before running the command?
Prompt 5
Generate a Primitive image using all available shape types in a single batch command so I can compare the results.
Open on GitHub → Explain another repo

← fogleman on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.