CLI tool
MtnViewJohn/context-free avatar
MtnViewJohn/context-free

Context Free turns a written grammar into an image with millions of shapes

Context Free is a program that generates images from written instructions called a grammar. The program follows the instructions in a few seconds to create images that can contain millions of shapes.

554 stars33 forksC++GPL-2.0

At a glance

What is it?
Context Free is a C++ program that renders images from a CFDG grammar, a recursive set of rules that the renderer expands into a shape tree, and it ships a command line tool, a Mac GUI and a Windows GUI. It suits an artist who wants generative work driven by rules rather than by hand, and it needs flex, bison, libpng and libicu before it will build on Linux.
Who is it for?
Context Free fits an artist or programmer who wants a picture produced by recursive rules rather than by hand, and who is comfortable with a grammar that has its own notation. It does not fit a workflow that needs a modern pipeline or a maintained package, because the last push was on 2026-10-11 with no GitHub releases published, and the Linux build asks for flex, bison, libpng and libicu before it will compile.
Can I use it commercially?
Yes, with conditions. GPL-2.0 is a copyleft licence: if you distribute software that includes it, you must release that software's source code under the same licence. Running it internally without distributing it does not trigger that obligation.
Is it still maintained?
Yes. The repository last received commits 2 days ago.
What is it written in?
Mainly C++, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on October 22, 2026, and from our analysis. They are not legal advice.

Editorial analysis

The input is a grammar, not a drawing

The project describes itself in one sentence that contains the whole idea: Context Free is a program that generates images from written instructions called a grammar, and it follows the instructions in a few seconds to create images that can contain millions of shapes.

The grammar is written in a notation called CFDG, and the mechanism is recursive rule expansion. A rule says what a shape looks like, and each rule can refer to other rules, including itself, with transformations applied between them. The renderer walks that tree and produces the final image. The Makefile's list of engine sources makes the implementation visible: there is cfdg.cpp, cfdgimpl.cpp, renderimpl.cpp, builder.cpp, shape.cpp, variation.cpp, and an AST layer with ast.cpp, astexpression.cpp and astreplacement.cpp, plus a rendererAST.cpp.

Two details in that source list hint at how the output is produced. There is an SVGCanvas.cpp alongside pngCanvas.cpp, so SVG is a first class output rather than an afterthought, and there is a tiledCanvas.cpp, which is how an image containing millions of shapes is rasterised without holding it all in memory at once.

The randomised element is named for it: Rand64.cpp and a variation.cpp, and a shapeSTL.cpp. The same grammar therefore does not produce the same picture twice, which is the point of the tool rather than a side effect.

Building on Linux needs flex, bison, libpng and libicu

The build notes for BSD, Linux, Unix and Posix systems are specific about the toolchain. You need a C++ compiler, gcc 7 or clang 4, flex 2.6 and not lex, bison 3.0, the libpng library and the libicu library, which is the International Components for Unicode package. The notes point out that most of this is installed or easily available on a modern distribution, and that for libpng and libicu you need the full installation of header files rather than just the runtime.

On Debian and Ubuntu that means the libpng-dev and libicu-dev packages, plus libfl-dev for the flex output. The Makefile assumes libpng and libicu live either with the system libraries or at /usr/local/lib, and if either is installed somewhere else you have to edit the LIB_DIRS variable in the Makefile to point at it.

The build itself is one command from the top level.

bash
    $ make

The notes warn that you will see a warning about mktemp and mkstemp during the link step, and that it can be ignored, which is the sort of detail that saves an hour the first time you build it.

Two more targets matter. 'make check' will test your compiled cfdg executable, and 'sudo make install' will install cfdg and the cfdg.1 man page in /usr/local. The repository ships a cfdg.1 man page at the root, so the tool has conventional Unix documentation rather than only a README.

Rendering from the command line

The command line tool is the simplest way to see what the program does, and the README gives the invocation directly.

bash
    $ ./cfdg -s 500 input/mtree.cfdg mtree.png

That reads the sample grammar from the input directory and writes a PNG. The -s flag sets the size, 500 in this case, and the two positional arguments are the grammar file and the output file. The input directory ships a set of named grammars, including mtree_v2.cfdg and mtree.cfdg, along with lesson and lesson2, demo1 and demo2, snowflake, sierpinski, rose, funky_flower, octopi, quadcity, triples, tangle, underground, ziggy, i_curves, i_pix, i_polygons, weighting_demo and welcome, in both _v2 and original forms.

Those file names are the quickest way to understand the notation, because they range from a first lesson to a weighting demo.

For the full option set there is a usage summary.

bash
    $ ./cfdg -?

The engine also supports SVG output, which matters if you intend to post-process the result in a vector editor rather than look at a raster. The engine source list includes a tiledCanvas, and the anti-grain geometry subset in src-agg provides the rendering primitives, which is why the source tree carries files such as agg_bezier_arc.cpp, agg_curves.cpp and agg_trans_affine.cpp alongside the CFDG engine in src-common.

There is also an FFmpeg path. A separate README.ffmpeg covers building ffmpeg and enabling ffmpeg support, with src-ffmpeg/ and src-ffmpeg/include/ in the tree, which is how the program can produce video rather than only still images.

One engine, three platform front ends

The source tree is organised around a shared engine with platform-specific front ends, and the layout makes the maintenance burden visible.

src-common/ holds the CFDG engine. src-unix/ holds the Unix and Posix specifics including pngCanvas.cpp, posixSystem.cpp, posixTimer.cpp and posixVersion.cpp. src-osx/ holds the Mac specifics, and src-mfc/ holds the Windows MFC sources for the older GUI path. src-win/ holds Windows resources including icons and the NSIS installer files under src-win/win-install/.

The GUI is built on Scintilla, with src-scintilla and src-lexilla present, and src-mfc/ for the classic Windows UI. The Mac GUI is an Xcode project at the top level, Context Free.xcodeproj, and the build notes say it requires Xcode 9 and Mac OS X 10.7 Lion, developed with Xcode 9 and 10 and Mac OS X 10.14 Mojave, and that it has not been tested with older versions.

Windows has two solutions: a VS2019 solution file for the GUI at ./src-net/ContextFreeNetVS11.sln and a CLI solution at ./ContextFreeCLIVS11.sln, both requiring Visual Studio 2022 or later. There is also a test.ps1 at the root, a Windows test runner.

The one wrinkle worth knowing about the Windows build is the parser. If you modify cfdg.l or cfdg.ypp then you must rebuild the parser files in src-win/derived, and the derived directory ships pre-built output from flex and yacc for people who do not have those tools. If you have Cygwin or a Unix, Linux or Mac system, you can cd to src-win/derived and type make, and you will need bison and flex to do it.

Test scripts and example generators that the README does not describe

Several scripts sit in the repository root and are worth knowing about, even though the README does not explain them in detail.

There is runtests.sh, which is presumably the entry point for the example test suite, and rungallery.sh, which suggests running a gallery of the sample grammars. There is makeexamples.py, a Python script, which is the most likely place where the example images are generated, probably by calling cfdg once per grammar.

There is also a debian/ directory, which means the project has been packaged for Debian at some point, alongside the ChangeLog file that records the release history since the source predates GitHub releases.

The absence of GitHub releases is worth noting on its own. The repository has no published releases, so the version you get is whatever the source tree says. The README header carries the version directly, and it reads version 3.4.3, with the copyright lines that follow: Context Free Copyright 2005-2026 Mark Lentczner and John Horigan, CFDG Copyright 2005 Chris Coyne, and the Anti-Grain Geometry library Copyright 2002-2005 Maxim Shemanarev.

That header also names the original authors, Chris Coyne, John Horigan and Mark Lentczner, and the project homepage is contextfreeart.org. The last push to the repository was on 2026-10-11, so the code is still being touched.

Licence, and what that means for the art you make

Context Free is released under the GNU license, specifically version 2 of the GNU General Public License or, at your option, any later version, and the full notice is reproduced in the README with the standard warranty disclaimer.

That is the permissive-with-copyleft end of the GPL family, and it has two consequences that are easy to confuse.

For the program itself, GPL-2.0-or-later means you can redistribute and modify it, and if you ship a modified binary you have to offer the corresponding source. If you only use it to make pictures, none of that touches you, because the output is not a derivative work of the program in any sense that the licence addresses.

For the art, the practical question is whether your generated image is a derivative of the program's source code. It is not. The output is the result of running the grammar, and the licence attaches to the software and the grammar files, not to the pictures. That is the same reasoning that applies to a compiler or a renderer, and it is the reason generative-art tools are commonly released under GPL.

The one thing to watch is the input grammar. The sample grammars in input/ ship with the project under the same licence, and if you take one as a starting point for your own work, you are working from GPL-licensed text. The licence file at the repository root is LICENSE.txt.

Where Context Free is the wrong tool

Three situations argue against it.

The first is a modern pipeline. There is no package on PyPI or a Homebrew formula mentioned in the README, no CI configuration described, and the Linux build needs flex, bison, libpng, libicu and libfl-dev plus a Makefile edit if your libraries live somewhere unusual. The Mac build wants an Xcode project last developed against Xcode 10, and the Windows build wants Visual Studio 2022 with a manual parser rebuild step if you touch the grammar syntax files. Every platform has a step where you have to know more than the README tells you.

The second is a need for still images at scale. The generator produces output from a grammar, and if your goal is a specific composition rather than a family of related compositions, writing the shape by hand in a vector editor is faster and gives you exact control. Context Free is for work where the rule set is the point.

The third is speed of iteration on the grammar itself. The editor for a CFDG grammar is the GUI, which means running the program, editing in Scintilla, and re-rendering. The README describes the whole program as following the instructions in a few seconds to create images that can contain millions of shapes, which is fast for the output but still a render cycle per edit.

The alternative in the same direction is another generative art system with a text grammar and a live preview, some of which run in a browser and need no compilation at all. The difference in approach is that those trade the CFDG notation and the mature shape system for immediate feedback and no toolchain. If you want to make art this week rather than set up a C++ build to do it, and the existing gallery of sample grammars is not already enough, the browser-based options cost you less for the same outcome.

Editorial conclusion

Context Free fits an artist or programmer who wants a picture produced by recursive rules rather than by hand, and who is comfortable with a grammar that has its own notation. It does not fit a workflow that needs a modern pipeline or a maintained package, because the last push was on 2026-10-11 with no GitHub releases published, and the Linux build asks for flex, bison, libpng and libicu before it will compile. Build it with `make`, render the sample tree with `./cfdg -s 500 input/mtree.cfdg mtree.png`, and only then decide whether the GUI is worth the extra toolchain.

Frequently asked questions

What is Context Free and what does it generate images from?

Context Free is a program that generates images from written instructions called a grammar, written in the CFDG notation. The renderer expands the recursive rules into a shape tree, which is how an image can contain millions of shapes.

How do I build Context Free on Linux?

Install a C++ compiler (gcc 7 or clang 4), flex 2.6, bison 3.0, libpng and libicu with their development headers, plus libfl-dev on Debian and Ubuntu, then run `make` from the top level. The README notes you can ignore the mktemp and mkstemp warning during the link step.

How do I render an image with the cfdg command line tool?

Run `./cfdg -s 500 input/mtree.cfdg mtree.png` to render the sample tree grammar at size 500 into a PNG. The `-?` flag prints a usage summary, and `make check` tests the compiled executable while `sudo make install` installs cfdg and the cfdg.1 man page into /usr/local.

What licence is Context Free released under?

The GNU General Public License, version 2 or any later version at your option, with the notice reproduced in the README and the licence file at the repository root as LICENSE.txt. The copyright lines cover Context Free 2005-2026, CFDG 2005 Chris Coyne and the Anti-Grain Geometry library 2002-2005 Maxim Shemanarev.

Does Context Free support SVG and video output?

The engine sources include an SVGCanvas alongside the PNG canvas and a tiled canvas, and the repository ships src-ffmpeg/ with a separate README.ffmpeg explaining how to build ffmpeg and enable ffmpeg support in the program.

Official sources

  1. Issues
  2. License: GPL-2.0
  3. MtnViewJohn/context-free on GitHub
  4. Project website
  5. README
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/mtnviewjohn-context-free.svg)](https://hysenlabs.com/projects/mtnviewjohn-context-free)

Was this useful?