-
-
Save sfm1234/c5916c7de62980b4a2a1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 hidden or 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