Skip to content

Instantly share code, notes, and snippets.

@brehaut
Created November 9, 2011 01:17
Show Gist options
  • Save brehaut/1349993 to your computer and use it in GitHub Desktop.
Save brehaut/1349993 to your computer and use it in GitHub Desktop.
l-system generator
function l_system (productions, depth, s) {
if (depth === 0) return s;
return $.map(s, function (v) {
return l_system(productions, depth - 1, productions(v) || [v]);
});
}
function run_turtle (turtle, operations, commands) {
$.each(commands, function (_, c) {
(operations[c] || $.noop)(turtle);
});
}
def l_system(productions, depth, s):
if depth == 0: return s
return (x for c in s for x in l_system(productions, depth-1, productions.get(c, [c])))
def run_turtle (turtle, operations, commands):
return reduce(lambda acc, c: operations.get(c, lambda t:t), turtle, commands)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment