using context-free grammars to generate CDFG files

If you have a design you're proud of, share the cfdg file here. It's also a good place to ask for feedback and collaborate.

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
futrelle
Posts: 15
Joined: Sat Jun 11, 2005 5:59 pm

using context-free grammars to generate CDFG files

Post by futrelle »

This grammar:

startshape r2
rule r1 0.753 {
SQUARE { x 0.06 y 1.89 s 0.77 r 1.350 b 0.7 }
SQUARE { x -1.180 y -0.943 s 0.46 r -97.1 b -0.4 }
}

rule r2 0.624 {
r2 { x 1.72 y 0.9 s 0.123 r -0.599 b 0.4 }
CIRCLE { x -0.354 y 1.833 s 0.74 r -42.60 b -0.1 }
r2 { x -0.758 y 1.6 s 0.7217 r 2.75 b 0.5 }
}

rule r2 0.948 {
r1 { x -0.9 y -1.5 s 1.9565 r 03.43 b 0.7 }
SQUARE { x -0.6 y -1.3 s 1.75 r 79.5 b 0.2 }
r1 { x -1.531 y 0.247 s 0.676 r 3.5 b -0.7 }
r2 { x 0.677 y 1.988 s 0.84 r -7.807 b -0.6 }
CIRCLE { x -0.3 y -0.218 s 0.7746 r -0.959 b 0.7 }
}

rule r2 0.902 {
r1 { x 0.11 y 1.9 s 0.6518 r 59.179 b -0.9 }
r2 { x -0.508 y -1.9 s 0.805 r 62.77 b 0.2 }
CIRCLE { x -0.560 y -1.20 s 0.9863 r 9.05 b -0.4 }
CIRCLE { x 0.513 y -0.0 s 0.9628 r 78.1 b 0.2 }
}

was generated by this rmutt grammar. It's ugly, because rmutt doesn't directly support random numbers:


grammar:
"startshape " rulename "\n"
rule{4}
;

rule: "rule " rulename " " prob " " rulebody "\n";

rulename: "r" ("1"|"2");
rulebody: "{\n" shape_clause rulename_clause* "}\n";
shape_clause: shape " " shapemod "\n";
rulename_clause: rulename " " mod "\n";
clause: shape_clause | rulename_clause;
shape: "SQUARE"|"CIRCLE";
mod: "{ x " nxy " y " nxy " s " ns " r " nr " b " nb " }";
shapemod: "{ x " nxy " y " nxy " s " nss " r " nr " b " nb " }";
nxy: "-"? "0." digit{1,3};
ns: "0." highdigit digit{1,3} &20 | "1." digit{1,3};
nss: ("0"&4|"1"&2|"2") "." highdigit digit{1,3};
nr: "-"? digit{1} "." digit{1,3};
prob: ns;
nb: "-"? "0." digit;
highdigit: "9"&9|"8"&8|"7"&7|"6"&6|"5"&5|"4"&4|"3"&3|"2"&2|"1";
digit: "0"|"1"|"2"|"3"|"4"|"5"|"6"|"7"|"8"|"9";
--
Joe Futrelle

User avatar
chris
Site Admin
Posts: 72
Joined: Wed May 04, 2005 10:57 am
Location: New York, NY
Contact:

pretty cool

Post by chris »

That's fun!

I actually have a random cfdg generator now, along with a "mutator" program that randomly changes things in cfdg's (both rules and values), and I've been toying around with a genetic selection process to make cool images. The last part isn't working so well.. How do I tell if something is cool? Heh...if it starts producing anything of value, I'll release it sometime soon.
Current Project: I'm creative director of OKCUPID at http://www.okcupid.com

User avatar
mtnviewmark
Site Admin
Posts: 81
Joined: Wed May 04, 2005 12:46 pm
Location: Mountain View, CA
Contact:

Re: pretty cool

Post by mtnviewmark »

chris wrote:How do I tell if something is cool? Heh...
You generate sixteen genetic variations, display them on the screen for the user, and let the user pick one, two or three. Then you proceed from those.
I'm the "m" in "mtree.cfdg"

User avatar
chris
Site Admin
Posts: 72
Joined: Wed May 04, 2005 10:57 am
Location: New York, NY
Contact:

Re: pretty cool

Post by chris »

MtnViewMark wrote:
chris wrote:How do I tell if something is cool? Heh...
You generate sixteen genetic variations, display them on the screen for the user, and let the user pick one, two or three. Then you proceed from those.
I was considering something like that, with a web interface...which is actually a lot like something I saw in a science museum once. Another variation (which I've already made) is one that compares them to a jpeg, until it can find a grammar that draws your face -- or whatever -- well. It's gotten horrible results so far, though. I need to get smart about analyzing the jpeg.
Current Project: I'm creative director of OKCUPID at http://www.okcupid.com

Post Reply