Pycontextfree is a library for creating images with Python by defining a set of generative rules. This approach is inspired by CFDG tool, yet unlike CFDG where special language is used, with pycontextfree rules are written in pure Python. This gives you extra flexibility by allowing to combine probabilistic rules with pythonic control flow and, additionally, by exposing cairo-cffi backend. In essence pycontextfree provides a set of drawing primitives, nested scopes of transformed geometry and photometry, and a mechanism to use Python functions as probabilistic rules. So that you can write something like this (on the left) and get something like that (on the right):
1 2 3 4 5 6 7 8 9 10 11 12 13 14
from contextfree import * @check_limits def branch(): line(0, 1) with translate(0, 0.9): with scale(0.7 + rnd(0.15)): with color(alpha=0.95): with rotate(rnd(40) - 40): branch() with rotate(rnd(40) + 40): branch() init(canvas_size=(300, 300)) branch() display_ipython()
pip3 install pycontextfree. For mode details, take a look at the tutorial , API refence and examples in the gallery.
If you would like to support the project, feel free to buy me a coffe