Join 3,494 readers in helping fund MetaFilter (Hide)


Context Free
July 7, 2005 10:42 AM   Subscribe

Context Free: A small language for design grammars. These grammars are sets of non-deterministic rules to produce images. The images are surprisingly beautiful, often from very simple grammars. And you can download and play on your own.
posted by signal (21 comments total) 6 users marked this as a favorite

 
See also the POV-Ray Short Code Contest.
posted by abcde at 11:00 AM on July 7, 2005


This is cool, although I don't know if these constitute linguistic grammars per se. I'd like to wrap a gui around it that used sliders and icons so my younger kids could play with it.
posted by mecran01 at 11:04 AM on July 7, 2005


From their web page:
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 two terminals are the shapes CIRCLE and SQUARE. 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!
I'd say that the files that make up an "instruction" for the drawing program are a linguistic grammar beyond a shadow of a doubt, although not the kind of grammar you would use for anything but a computer. Humans demand a bit more complexity in their grammars. Computers like it stupid.

These things are amazing, but I need to avoid devoting hours to this diversion when I have real work to be done. :-(
posted by teece at 11:26 AM on July 7, 2005


suh-WEET. Nice 'n' elegant. I'm thinking immediately of toy VR (e.g., second life) and gaming uses, but it could also be a good visualization tool for reasoning about CFGs.
posted by gurple at 11:49 AM on July 7, 2005


It takes me back about 22 years to my first time programming in Logo. We didn't get pictures with this kind of resolution, but I sure did get the idea that recursion is cool.
posted by Wolfdog at 1:05 PM on July 7, 2005


Ditto that on Logo. It's only been about 18 years for me, but Logo was a really cool way into programming (even though it wasn't for me) and logic.

Logo is still available, and can be had on most modern platforms, I recently realized.
posted by teece at 1:10 PM on July 7, 2005


I kind of like this one:
startshape NAUT
rule NAUT {
CIRCLE {s 0.15}
NAUT {y 0.16 r -5 s 0.99}
}
rule NAUT 0.125 {
CIRCLE {s 0.15}
NAUT {y 0.16 r -5 s 0.99}
NAUT {x 0.89 r 185 s 0.257}
}

posted by Wolfdog at 1:25 PM on July 7, 2005


Uh-oh. I feel another addiction coming on....

Thanks, signal! (Though my wife will [quietly] damn your soul for this....)
posted by mmahaffie at 1:26 PM on July 7, 2005


Wolfdog: that is pretty, fun to play with, too.
mmahaffle: tell her it’s already been damned many times before.

Can anybody smarter than me explain if these are L-Systems and if (as I suspect) not, why not?
posted by signal at 2:22 PM on July 7, 2005


Thanks, I couldn't really understand what the FPP meant, but I'm glad I clicked through because they are pretty cool.
posted by OmieWise at 3:32 PM on July 7, 2005


I hate you signal. but thanks!
posted by arse_hat at 4:34 PM on July 7, 2005


startshape DEATHSTAR
rule DEATHSTAR 100 {

CIRCLE {
size 0.2
}

DEATHSTAR {
y 0.08
rotate -1
size 1
b 0.000005
}
}

rule DEATHSTAR 0.5 {

DEATHSTAR {
size 0.999
rotate 0.1
}
}

rule DEATHSTAR 0.002 {

DEATHSTAR {
size 0.9
rotate 0.1
}

DEATHSTAR {
size 0.6
rotate 1
}
}


Whee.
posted by Tlogmer at 4:35 PM on July 7, 2005


arse_hat: right now, I hate myself:

startshape FROND

rule FROND {
SQUARE{}
FROND {y 1}
}

rule FROND 0.15 {
CIRCLE {x 1}
CIRCLE {x -1}
FROND {r 90 s 0.5 b 0.2}
FROND {r -90 s 0.5 b 0.2}
FROND2 {}
}

rule FROND2
{FROND{s 0.85}}

rule FROND2 0.5 {
SQUARE {s 2 b 0.5}
}

rule FROND2 0.05 {
CIRCLE {x -0.5 y -0.5}
FROND {x -0.5 y -0.5 r 45}
}

posted by signal at 5:41 PM on July 7, 2005


This is a fantastic post!!
posted by odinsdream at 6:31 PM on July 7, 2005


I can stop anytime I want to:
startshape SQUARES

rule SQUARES {
SQUARE {b 0.8 x 0.1}
SQUARE{b 0 s 1}
SQUARE{b 1 s 0.9}
SQUARES {s 1 y 0.9 r 2}
}
rule SQUARES 0.3 {
SQUARES {s 0.5 x 1 r 90}
SQUARES {}
}
rule SQUARES 0.1 {
SQUARES {s 0.5 x 1 r 45}
SQUARES {}
}
rule SQUARES 0.1 {
SQUARES {s 0.9 x 1 r -90}
SQUARES {}
}
rule SQUARES 0.3 {
CIRCLE {b 0 s 1 r 90}
}

posted by signal at 7:33 PM on July 7, 2005


Thanks Signal, from yet another Logo kid from the '80s.
posted by shoepal at 7:58 PM on July 7, 2005


Can anybody smarter than me explain if these are L-Systems and if (as I suspect) not, why not?

I don't even know what an L-system is, but a post about Koch snowflakes on the Context Free web site says that, A) a Koch triangle is an L-system, and that B) Context Free is not made for such things.

Of course, someone then proceeds to make a Koch snowflake with Context Free.

The thread is here.

And this is great stuff, signal. Thanks.
posted by teece at 8:58 PM on July 7, 2005


[this is pretty awesome]
posted by neckro23 at 9:29 PM on July 7, 2005


very cool--thanks!
posted by amberglow at 10:24 PM on July 7, 2005


signal, the wikipedia page on l-systems answers your question, i think - an l-system grammar can be more complex, in that it can include some information about context. by definition, context free grammars can't.

i'd not heard of l-systems before, but looking at them, the definition is pretty broad, so they can cover a range of chomsky grammar types. i guess they were dreamt up before or independently of his work (yeah, i should read the whole page ;o)

so, for example, an l-system can respond to its environment (the context), in a limited fashion, while things defined in this (cool) package simply grow "blindly".

another way of saying the same thing - if you zoom in on a particular point, you can predict, at that single point what will follow. since the same rule is used everywhere, that means you get fractal/self-similar patterns. with a l-system that might be true too, but it is also possible that you will need to look at more that the one point before you can work things out - like maybe the preceding two points, or more.

really cool link - thanks.
posted by andrew cooke at 2:37 PM on July 8, 2005


Here's some code to generate random vertical and horizontal domino tiles. I wish I was saavy enough to make this into something that generates a random domino board:


startshape DOMINOES

rule DOMINOES {
DOMINO{}
}

rule DOMINO{
HORIZONTAL{}
}

rule DOMINO{
VERTICAL{}
}

rule HORIZONTAL{
VERTICAL { rotate 90 }
}

rule VERTICAL{
V_OUTLINES{}
U_V_DOTS{}
L_V_DOTS{}
}

rule V_OUTLINES{
SQUARE { x 1 y 1 s 1 b 0 }
SQUARE { x 1 y 2 s 1 b 0 }
SQUARE { x 1 y 1 s .95 b 1 }
SQUARE { x 1 y 2 s .95 b 1 }
}

rule U_V_DOTS{
}

rule U_V_DOTS{
CIRCLE { x 1 y 2 size .17 }
}

rule U_V_DOTS{
CIRCLE { x .8 y 2 size .17 }
CIRCLE { x 1.2 y 2 size .17 }
}

rule U_V_DOTS{
CIRCLE { x .8 y 2.2 size .17 }
CIRCLE { x 1 y 2 size .17 }
CIRCLE { x 1.2 y 1.8 size .17 }
}

rule U_V_DOTS{
CIRCLE { x .8 y 2.2 size .17 }
CIRCLE { x 1.2 y 2.2 size .17 }
CIRCLE { x 1.2 y 1.8 size .17 }
CIRCLE { x .8 y 1.8 size .17 }
}

rule U_V_DOTS{
CIRCLE { x .8 y 2.2 size .17 }
CIRCLE { x 1.2 y 2.2 size .17 }
CIRCLE { x 1 y 2 size .17 }
CIRCLE { x 1.2 y 1.8 size .17 }
CIRCLE { x .8 y 1.8 size .17 }
}

rule U_V_DOTS{
CIRCLE { x .8 y 2.2 size .17 }
CIRCLE { x 1.2 y 2.2 size .17 }
CIRCLE { x .8 y 2 size .17 }
CIRCLE { x 1.2 y 2 size .17 }
CIRCLE { x 1.2 y 1.8 size .17 }
CIRCLE { x .8 y 1.8 size .17 }
}

rule L_V_DOTS{
}

rule L_V_DOTS{
CIRCLE { x 1 y 1 size .17 }
}

rule L_V_DOTS{
CIRCLE { x .8 y 1 size .17 }
CIRCLE { x 1.2 y 1 size .17 }
}

rule L_V_DOTS{
CIRCLE { x .8 y 1.2 size .17 }
CIRCLE { x 1 y 1 size .17 }
CIRCLE { x 1.2 y .8 size .17 }
}

rule L_V_DOTS{
CIRCLE { x .8 y 1.2 size .17 }
CIRCLE { x 1.2 y 1.2 size .17 }
CIRCLE { x 1.2 y .8 size .17 }
CIRCLE { x .8 y .8 size .17 }
}

rule L_V_DOTS{
CIRCLE { x .8 y 1.2 size .17 }
CIRCLE { x 1.2 y 1.2 size .17 }
CIRCLE { x 1 y 1 size .17 }
CIRCLE { x 1.2 y .8 size .17 }
CIRCLE { x .8 y .8 size .17 }
}

rule L_V_DOTS{
CIRCLE { x .8 y 1.2 size .17 }
CIRCLE { x 1.2 y 1.2 size .17 }
CIRCLE { x .8 y 1 size .17 }
CIRCLE { x 1.2 y 1 size .17 }
CIRCLE { x 1.2 y .8 size .17 }
CIRCLE { x .8 y .8 size .17 }
}

posted by odinsdream at 10:31 PM on July 8, 2005


« Older "More than 10-million U.S. homes are equipped with...  |  Alarming Article on Security P... Newer »


This thread has been archived and is closed to new comments