Wave function collapse is an algorithm that generates bitmaps locally similar to an input bitmap. The algorithm turns the task into a constraint satisfaction problem; the solution space consists of images which satisfy some definition of "locally similar", and images can then be sampled from this space.
This repository contains an online demo and commented Typescript re-implementation of Maxim Gumin's original C# implementation (https://github.com/mxgmn/WaveFunctionCollapse).