Created
September 18, 2019 16:21
-
-
Save mayakraft/d4f4a1110e995935c8cd653927528249 to your computer and use it in GitHub Desktop.
a concise way of writing L-systems in Javascript. this rule set is the dragon curve
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
var rules = { | |
X: "X+YF+", | |
Y: "-FX-Y" | |
}; | |
function rewrite(str) { | |
var s = ""; | |
for (var i = 0; i < str.length; i++) { | |
if (rules[str[i]] !== undefined) { | |
s += rules[str[i]]; | |
} else { | |
s += str[i]; | |
} | |
} | |
return s; | |
} | |
// call n times | |
rewrite(rewrite(rewrite("FX"))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment