This is Go implementation of carpet fractals. What is a carpet fractal? One famous example is the Sierpinski carpet:
How does the Sierpinski carpet work? You take a white image of 1×1 pixel. A white pixel will be replaced by 3×3 pixels which are black except for the center white one. Successively, white pixels will be replaced by white 3×3 pixels and black pixels will be replaced by the mentioned almost-black pattern. The number of iterations will define the size of your image and level of detail.
In essence, I watched jrhodkinson’s “Carpets, Genetics, and the Pi Fractal” talk and was amazed by the beauty. So I implemented it.
This implementation allows you to generate images of such structure. You can define the rules/patterns by yourself. You can either get the binary executable or use this implementation as a go dependency.
-
Go to the releases tab
-
Download the executable appropriate for your computer architecture
-
Start the executable (Linux: with your favorite shell, Windows: powershell or cmd.exe) without arguments to get usage information
-
Start the executable with proper arguments.
-
Look at the cool images
Wait… proper arguments? Can I have some simple example please?
-
Go to the releases tab
-
Download the executable appropriate for your computer architecture
-
Download the github repository (click on the green button "Clone or download" and "Download ZIP")
-
Decompress the github repository files and put the executable in its root folder
-
Start your favorite shell, PowerShell or cmd.exe
-
Change directory to the root of the github folder
-
Run
carpet examples/sierpinski 6 out.png
-
Open the
out.png
image in your image viewer and be amazed by its beauty.
-
A filepath to a directory containing rule files. Rule files must be square PNG files with filenames matching
rule-<RGBA-color>.png
where<RGBA-color>
is a placeholder for a 8-character hexadecimal representation of a RGBA color. -
The number of iterations to apply to generate the image
-
The output PNG file path
-
The initial color (what is the color the generating image is painted with?) as 8-character hexadecimal representation of a RGBA color
Available at github.
Please submit any feedback at Github.
See the LICENSE file (Hint: MIT license).