Pattern Generator

As part of my numbers station project (write-up coming soon), I needed the ability to automatically generate a unique and distinctive image based on an input value.

Here are some examples of the final output!

How Does It Work?

The algorithm is inspired from a quilting method called the nine-patch or nine-block. Every new pattern is created from a set of base shapes:

The goal is to create a 3x3 grid made up of three of these shapes. First, a shape is randomly picked for the center of the 3x3 grid. In the standard nine-patch method, the center shape must be a symmetric, one of 1, 5, 9, or 19 (the empty shape). However in my version I allow any shape to reside in the center. Next, we randomly pick a corner shape, and a side shape, as well as an initial orientation for both. Orientations are always multiples of 90 degrees.

For step one, let's say we pick the 16th shape (the large circle) as our center shape.

Next we pick the 6th shape for our corner. We place it in the top left of the 3x3 grid with a rotation of 0. Next we rotate it 90 degrees, and place it in the top right. Rotate again and place it in the bottom right. Finally we rotate once more and place it in the bottom left. After doing this we get the following image.

For the side shape we pick shape number 3 (the large triangle). We place it on the left side with an initial orientation of 270 degrees. We rotate 90 degrees and place it on the top, and repeat the process for the right and the bottom. This gives us the following image.

As our final step, we repeat this process across the entire image 10 times, and pick two random colors: one for the center and corners, and one for the sides. After this we get our pattern.