Recursive Pentagons
edv closed his/her discussion on Recursion, but it was too interesting of a challenge to pass up.
Attached is a simple network that creates the top example in the golden ratio chart edv supplied. It is somewhat recursive in the sense that each copy of the "newChild" subnetwork takes a parent pentagon and spits out a child pentagon that is sized down using the golden ratio and positioned to align with its parent. To create an arbitrarily deep chain of pentagons you just feed the first child into the second, the second into the third, etc.
The attached Pentagons.png screenshot displays the result for five pentagons and shows how simple the network is. The "newChild" network is also fairly simple with just a dozen nodes. It does a lookup on the length of the parent pentagon path and divides by a constant to determine the parent's radius. This is divided again by the golden ratio to create the child pentagon and also used to calculate the child's position.
You can resize the parent pentagon and all its descendants will follow along. The view in the screenshot shows a parent pentagon with a radius of 144, chid radius of 89, grandchild radius of 55, etc. just like the chart example.
Enjoy!
John
- Recursive_Pentagons.ndbx 14 KB
-
Pentagons.png 95.5 KB
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Rory on 31 Mar, 2015 09:49 AM
Very nice!
2 Posted by Garrett Milliro... on 02 Apr, 2015 12:01 AM
You were able to create a network that performed the recursive operation, and then copy the network node 4 times and combine their outputs.
However, the original question was regarding recursion support. Is there plans to create a node which you could attach the network node and select 4 recursions in order to create the same output?
This would be very handy.
Support Staff 3 Posted by john on 15 Aug, 2015 06:46 AM
Dear NodeBox staff,
Garrett makes a good point here. As far as I can tell, there is no way to do true recursion with NodeBox nodes (aside from calling Python procedures). True?
This seems like a strange omission. NodeBox claims to be a functional language yet the premise of other functional languages is that they use recursion in place of loops.
Have you guys ever thought about a way to allow recursive nodes? It's not immediately clear to me how to do this within the NodeBox paradigm, but there must be a way.
Maybe you could have a "Parent" node that could only be used inside a subnetwork. The parent node would take the same inputs as the subnetwork it resided in and, if activated, would execute that subnetwork.
To make a recursive factorial subnetwork you would compare the input to 0 and tie that boolean output to a rendered switch node. If true (1) the switch would return a 1; if false (0) it would return n * parent(n-1) - which you would construct out of multiply node, a subtract node, and a parent node.
If that wouldn't work, perhaps you could come up some other way of allowing recursion. I sure wish I had something like this for the project I'm working on at the moment.
Any thouughts?
John