Clone this wiki locally
What is this thing?
Chris Coyne created a small language for design grammars called CFDG. These grammars are sets of non-deterministic rules to produce images. The images are surprisingly beautiful, often from very simple grammars.
Context Free is a full graphical environment for editing, rendering, and exploring CFDG design grammars.
- Simultaneously available for Macintosh, Windows and Posix/Unix.
- Progressive image update: watch it generate
- Save generated images in PNG or SVG format.
- Produce animations
- Edit grammars and re-render easily.
- Render very large images (as large as 100 Mega-pixels).
- Can handle generated images with millions of shapes.
- Carefully tuned graphics rendering
- Many built-in examples
- Automatic checking for updates (Mac only).
- It's free, as in beer and as in speech.
How do I get started?
First, download and install the program.
Second, run the program and try the things in the Examples menu. Just pick something in that menu, it will open and start generating an image.
Third, choose "Render" from the Render menu, or click the "Render" button (or just type command-R). Most of the rule sets have some random aspect to them and so will generate different images each time.
Fourth, choose lesson from the Examples menu. Read it. Yes, read it, there are lots of comments in the rules. They should explain how rules work. How the heck is it doing that?
Context Free lets you write a set of rules about how to generate an image, and then follows those rules to create a image. The rules define each shape to be made up of other shapes.
The image generation process goes something like this:
- Start with a just the startshape on the to do list.
- Now, pick something from the to do list. If the shape is a circle, square, or triangle, then draw it.
- Otherwise, find the rule for that shape. If a shape has more than one rule, then pick one randomly.
- Put each shape listed in the rule back on to the to do list. The rule may state that each of these new shapes should be rotated, scaled, relocated and/or brighter than the original shape.
- Continue from step 2 until the to do list is empty, or everything on it is too small to be seen.
Uh, okay, I'm not sure I got that...
What is it written in?
The bulk of Context Free is written in C++. It is shared between both Windows and Macintosh versions. The Windows version is built with .Net and Visual C++. The Macintosh version is in a mix of C++ and ObjectiveC++, and is built with Xcode. The Posix version uses libpng for rendering and writing PNG files.
All three versions use the incredibly gorgeous Anti-Grain Geometry 2D graphics library by Maxim Shemanarev. It performs very optimized high fidelity anti-aliased drawing that is pixel identical on all three platforms.
The complete source is free (GPL). See the Downloads page.
Any code worth snagging?
There is a nice system and user interface for managing the random seed and the scalable, distributed random number generators used to generate an image. This allows the user to reproduce an image. Steal it, please! (Credit appreciated, of course.)
How did this come to be?
Mark was reading about the recently popular (and Slashdotted) SCIgen - An Automatic CS Paper Generator. He noticed a small reference to Chris' CFDG work in the "related work" section. He was entranced and starting porting immediately. Then John and Mark barely slept for three weeks.
What are context free grammars?
A context free grammar is a description of a language in a set of rules. Each rule says how a single symbol can be expanded into a sequence of other symbols. Those symbols may, in turn, have rules and can be expanded again. Some symbols are terminals and have no rules. A legal sentence in the described language is a sequence of terminal symbols that can be produced starting with the start symbol of the grammar and proceeding via some sequence of expansions.
The process is considered context free because each expansion of a symbol via some rule can be done independently of any of the expansions of other symbols.
In Context Free, the only three terminals are the shapes TRIANGLE, CIRCLE, and SQUARE (actually, you can create custom terminals now). Given a starting shape, the program keeps expanding shapes that have rules until all that is left are terminal shapes, which are then drawn. In essence, the rendered images are legal sentences in the language described by the rules file!
For more about the mathematics of grammars, see Context-free grammar in Wikipedia.
Mark Lentczner saw Chris' site and decided he had to have an interactive version. He is responsible for the Macintosh version.
John Horigan got sucked into this project and it immediately ate all of his spare time. He wrote the Windows version. Mark and John jointly maintain the common code base and the Posix/Unix version.
Electronic Frontier Foundation for fighting the good fight
GNU Project for inspiring us to make free software
Anti-Grain Geometry by Maxim Shemanarev is the beautiful, high fidelity 2D graphics library used in Context Free