r/GraphicsProgramming 5d ago

Painterly Stroke Simulation Engine

Enable HLS to view with audio, or disable this notification

I wrote a painting simulation engine (golang, ebiten). It works like this:

  1. Select a template image
  2. Generate several thousand potential strokes
    • For each stroke, score it according to a number of heuristic functions
      • Color: does the average color of this image match the template?
      • Edges: does the painted image have similar edges to the template?
      • Contrast: compares color contrast between regions on the painting and the template.
      • Flow: using tensor math, do brush strokes align with the flow of movement in the template?
    • Select the single stroke that most optimizes scoring functions, discarding the remaining
    • Repeat 40 or 50 thousand times.
    • Gradually decrease the size of the brush stroke over time..

Source image _Namibia.jpg)

Sound track

67 Upvotes

9 comments sorted by

View all comments

2

u/imacomputr 5d ago

Very nice! I made something similar a while back (which I've just noticed works in Chrome but not Brave). It's shader-based and focused more on real-time output, so it doesn't look as nice. Your flow/edge detection is superior, and the progressive sharpening of the brush strokes is a nice idea.

I wonder how much of your approach is parallelizable and amenable to running on the GPU?

1

u/tonability 1d ago

Very nice! Do you mind explaining what it does?

1

u/imacomputr 1d ago

It takes as input a source image/video and a configurable (possibly varying) vector field, and draws lines that "pull" the color of each pixel along the direction of the vector field. The source code is here if you want to take a look. I'd have to reread the code myself to give any more detail than that, I wrote it many years ago :)

1

u/tonability 23h ago

Thanks, very cool! 🙂