This is the P2PU Archive. If you want the current site, go to www.p2pu.org!

Creative Programming 2010

My recent threads

You haven't posted any discussions yet.

Recently updated threads

Anybody try Context Free yet?

Go back to: General discussion

We might as well get this started.  Has anybody played around with Context Free yet?  We don't have the sample CFDG files, but you can find the documentation at contextfreeart.org.  Also, you may want to check out Aza Raskin's ContextFree.js or the online sandbox for it, Algorithm Ink.

Personally, I'm finding it a little difficult to work with.  I'm having a much easier time with Processing.  If anybody is doing well with it, would you like to post your CFDG files with some comments added so that others can learn from them? 

bit stream's picture
bit stream
Sat, 2010-10-02 21:14

Hello

I start playing with the program. Basically, you state several rules, calling basic shapes (primitives), that could be recursive, and can be called with a given probability. For instance:

[code]
//tell the program how to begin
startshape Branch
//
rule Branch{
SQUARE{ h 30 sat 0.61 b 0.95} //render an square with hue, saturation, brightness
Branch{s 0.95 h 2 y 0.9 r 5 x -0.05}
/*
call Branch recursively, scaling each time 0.95, shifting hue by 2,
translating y by 0.9 units, rotate 5º, and translate x -0.05
*/
}
[/code]

The recursion stops when the shape scale reaches 0 units, this time. To change direction, we can add another rule, with the same name and different probabilities. The entire file will be:

[code]
startshape Branch
rule Branch 0.7{ //<--- probability
SQUARE{ h 30 sat 0.61 b 0.95}
Branch{s 0.95 h 2 y 0.9 r 5 x -0.05}
}
rule Branch 0.76{
SQUARE{ h 30 sat 0.61 b 0.95}
Branch{s 0.95 h 2 y 0.9 r -5 x 0.05}
}
[/code]

And to finish, the typical fractal (or something alike :P)

[code]
startshape Tree

rule Tree 0.9{
Branch{}
Tree[ r 25 x 3 y 6 s 0.9]
Tree[ r -25 x -1.8 y 4 s 0.9]
}
//ensures recursion finish
rule Tree 0.5{}
}
[/code]

A few things to note: square braces [] tells the program to respect
that order of operations. The second rule controls the amount of objects
rendered (because I have an old computer :P). And, each time we render, we'll
get a new drawing, as the rules have probabilities. But contextFree stores each
run with 3 letters, so we can recover it later.

Shall we put images here?

Brylie Oxley's picture
Brylie Oxley
Sun, 2010-10-10 17:27

I like the interface at Algorithm Ink (http://azarask.in/projects/algorithm-ink) but am having trouble getting the above examples to render correctly.

bit stream's picture
bit stream
Wed, 2010-10-13 12:47

It is a JavaScript port and doesn't work exactly the same as context Free does. The view doesn't resize automatically and colors also changes. My little test could be adapted:

startshape S

rule S{
Tree{s 0.05 y -1}
}

rule Branch 0.7{
SQUARE{ h 30 sat 0.61 b 0.95}
Branch{s 0.95 h 2 y 0.9 r 5 x -0.05}
}
rule Branch 0.76{
SQUARE{ h 30 sat 0.61 b 0.95}
Branch{s 0.95 h 2 y 0.9 r -5 x 0.05}
}
rule Tree 0.9{
Branch{}
Tree{ r 25 x 0.5 y 5 s 0.9}
Tree{ r -25 x -0.5 y 3 s 0.9}
}
rule Tree 0.3{}

Each time you click on the draw button, you'll get a new drawing.

Cheers!