Created
November 9, 2011 01:17
-
-
Save brehaut/1349993 to your computer and use it in GitHub Desktop.
l-system generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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