fractal-tree | My study on https :
kandi X-RAY | fractal-tree Summary
kandi X-RAY | fractal-tree Summary
You can see this running here.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of fractal-tree
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:
QUESTION
I found a nice example of a recursive function that generates a simple fractal tree here (shown below).
...ANSWER
Answered 2018-Jan-31 at 17:13The method used to move the line for each iteration does not track the position of the branch, but relies on the ctx.save()
and ctx.restore()
state stack functions to return the correct position to move to the next branch.
Using set timeout means that the restore is called before recursion has reached the last branch.
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