3 ms·
I can't figure out the grammar. I wanted to do the Hilbert curve at https://en.wikipedia.org/wiki/Hilbert_curve https://en.wikipedia.org/wiki/Hilbert_curve:
by dalke 3y ago
I can't figure out the grammar. I wanted to do the Hilbert curve at https://en.wikipedia.org/wiki/Hilbert_curve https://en.wikipedia.org/wiki/Hilbert_curve:
Alphabet : A, B
Constants : F + −
Axiom : A
Production rules:
A → +BF−AFA−FB+
B → −AF+BFB+FA−
I thought it might be:
A=|+[B]|−[A]|[A]-|[B]+
B=|−[A]|+[B]|[B]+|[A]−
but that doesn't work, and I don't know what's wrong.
- deosjr 3y agoI tried for a bit and couldn't get it to work either. The dragon curve example is a lot more complicated than the simplest definition, which is a hint. I don't even know exactly what | or [ or ] are supposed to do here. Here's a version in Go instead: https://github.com/deosjr/GenGeo/blob/master/gen/lindenmayer.go#L252 https://github.com/deosjr/GenGeo/blob/master/gen/lindenmayer... Which renders into: https://github.com/deosjr/GenGeo/blob/83c77f9433e569b30f71b33baf47e66a8a66940a/out.png https://github.com/deosjr/GenGeo/blob/83c77f9433e569b30f71b3... (see Algorithmic Beauty of Plants for way more examples)
- SomeDaysBe 3y agoI was able to get it working, I think: axiom: a rules: a = +b|-a|a-|b+ b = -a|+b|b+|a- initial angle: 90 angle change: 90 scale: 1 simulation depth: 4
- dalke 3y agoThat did the trick - thanks! I couldn't figure out what the [] meant in this context and thought it was to make a recursive call. (I've been working on basic space-filling curves, and came across that Wikipedia page last week, which is about all I know about L-systems.)
- SomeDaysBe 3y agoWow never heard of space filling curves. Yet another rabit hole to go into.
- dalke 3y agoJust posted my code as a "Show HN" at https://news.ycombinator.com/item?id=36762283 https://news.ycombinator.com/item?id=36762283 . The actual project is at https://hg.sr.ht/~dalke/rectfillcurve https://hg.sr.ht/~dalke/rectfillcurve . I've implemented a few space-filling curves and wrapped them into an iterator API.
- sp332 3y agoThe rules are in https://eliben.github.io/lsystem/rules.js https://eliben.github.io/lsystem/rules.js and the evaluation is in https://eliben.github.io/lsystem/lsys.js https://eliben.github.io/lsystem/lsys.js It looks like f and g are special rules for moving with the pen down or the pen up.