Another Fun House Language Called Context-Free
This tapestry of circles, believe it or not, was hacked out in just 12 lines of code.
startshape LIMIT
rule LIMIT {
4*{r 90 h 90} QUAD [r 45 x .5 y .5 h 45 sat 1 b 1 |b 0]
}
rule SHAPE {
SQUARE{a -.5}
CIRCLE{s .8 sat -1 b 1 a -.5 z 1}
}
rule QUAD {
SHAPE{} 2*{x -1 y 1}
QUAD [x .5 y -.5 s .618 x .5 y .5 b .15| h 90]
}
This is Square Limit I by AlliedEnvy and it’s written using the Context-Free Design Grammar. Which is basically LOGO with recursion and functions. You run your code and you get back a PNG.
This stuff really lights me up. So, there are three functions in this drawing: LIMIT
, SHAPE
and QUAD
. The most basic part is the SHAPE
, which is just a circle and square. The QUAD
function is a neat little tree-like function which draws a series of SHAPE
and then calls itself. The LIMIT
rotates 90 degrees and draws four QUAD
.
Then, from the commandline:
$ cfdg sqlimit1.cfdg sqlimit1.png
The trickiest part of all this is just how succinct it is. All the shape properties are listed here. But while x
and y
are obvious, attrs like size
can be abbreviated as s
and rotate
can be abbreviated as r
.
What really grabs me is that Context-Free is this tiny, unassuming language of just thirty or so parts. And it stops right there. It’s so tight and minimal. So you can create some rather delightful eyecandy in just ten or so lines. Some other really short examples are Alhambra, Spike, BW Circles, Hex Cloud, Orbido and Youthfulness.
bronson
Are you going to port any of this to Shoes? It seems like it would be pretty straightforward!
Matt B
Logo does have functions and recursion, by the way.
MenTaLguY
I think the key difference to Logo is that ContextFree is entirely declarative (versus Logo’s very procedural approach to drawing), and that it is not turing-complete (assuming no features were added which allow you to write context-dependent grammars).
This would be a cool thing to have in Shoes, really.
_why
Oh, here we go: an online interp. With a cheat sheet.
shev
I saw cfdg about two years ago…
it blew me away, especially some user-submitted .cfdg files. It was one of my favourite apps :)
Quilter
This is a great pattern for a quilt. Beautiful colours. I bet I can make this quilt out of scraps that I already have.
Oliver Steele
I love cfdg. I wrote Ruby and JavaScript interpreters for it a couple of years ago; I’ll clean them up and post them this weekend in case anyone wants to do anything with them.
Travis Reitter
This reminds me a lot of the syntax of POV-Ray, except 2D. Either way, it gets even more interesting when you generate this code from other programs :)
MenTaLguY
Oliver: anything that generates SVG, out of curiosity? Something I’ve wanted to see for a long time is a CFDG extension for Inkscape.
Tim
Logo is basically CFDG but with colors!
Zellyn
I came up with this after learning a bit of Nodebox and CFDG.
failrate
Another interesting doohicky out there for the 3D realm is alice.org
(More related to hacketyhack than CFDG, but there it is)
Comments are closed for this entry.