Skip to content

Instantly share code, notes, and snippets.

@sfm1234
Forked from brehaut/lsystem.js
Created July 30, 2014 18:43
Show Gist options
  • Save sfm1234/c5916c7de62980b4a2a1 to your computer and use it in GitHub Desktop.
Save sfm1234/c5916c7de62980b4a2a1 to your computer and use it in GitHub Desktop.
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