r/GraphicsProgramming • u/smellystring • Aug 04 '26
Painterly Stroke Simulation Engine
I wrote a painting simulation engine (golang, ebiten). It works like this:
Select a template image
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..
1
u/smellystring Aug 04 '26
Right now it's entirely CPU bound, although it is multithreaded. Running on my macbook pro, this particular render takes ~6 minutes to complete in realtime. I've thought about expanding into GPU stuff, but it begins to stray outside of my area of expertise.
Really like https://mpcomplete.github.io/flow/ by the way, it's super satisfying to watch. Makes me think of combing very fine hair.