fractal-tree | Fractal tree | Animation library
kandi X-RAY | fractal-tree Summary
kandi X-RAY | fractal-tree Summary
Fractal tree
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Creates a new branch
- push all nodes to the tree
- branching angle
- Draw the trees
- Set up the tree
- get leaves
- Calculates the next glyphs .
- min x .
- Calculates and returns an object
- step 1D
fractal-tree Key Features
fractal-tree Examples and Code Snippets
Community Discussions
Trending Discussions on fractal-tree
QUESTION
I wrote the program below in sml to generate a fractal tree into a web page (i'm pretty proud of it 😅). I used a recursive function, because there is no for loop in sml.
...ANSWER
Answered 2020-Oct-27 at 21:57Excellent work!
I'd like some help on the portion of the code that needs to be changed to turn this function into an iterative function.
I identify three parts of your code:
- The part that generates an SVG string
- The part that interacts with files
- The part that calls itself recursively
I would separate those parts so that you can compose them any way you like without depending deeply on the other. For example so that you can compose fractal effects without necessarily composing filesystem effects.
As for iteration vs. recursion, since you're in a functional language, I would recommend to continue with recursion. But because your recursive pattern is tree-shaped (every call potentially creates two other calls), your recursion risks overflowing heap memory.
So an iterative solution and a tail-recursive solution would achieve the same thing: Since you recurse both left and right, but not at the same time, you can explicitly rather than implicitly store, using a stack, that you're recursing the other way later, too.
Here is a rewrite; I'll comment below:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install fractal-tree
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page