NZ Ferns - sampling parametric curves and recursion

I still remember my intro programming professor, who went on to be a great undergraduate advisor, (shout out to A. Pang at UCSC), teaching our class about recursion. He asked if anyone had really looked at the structure of a fern and how each leaf is made up of many branching little leaves, with each little leaf sharing the same overall structure repeated, (i.e. many branching smaller leaves), etc. After lecture, I wandered out into UCSC's lovely grounds and found a fern leaf and really looked at it. I have always liked recursion (but like many of us, I sometimes shy away unnecessarily).

Here in New Zealand there are amazing giant fern trees and they've been cleverly incorporated into a lot of graphic design (including the almost winning revised 'silver fern flag')*

Photo of one of the many ferns we've seen


Kyle Lockwood's silver fern flag design By Kyle Lockwood - Traced from the design gallery for the New Zealand flag referendums, 2015–16See more information about this flag design., CC BY 3.0 nz, https://commons.wikimedia.org/w/index.php?curid=43422495




Inspired by all the natural and graphical ferns, I decided that would be my next toy and as Winslow is working on transforming functions in math. We sat together to find a polynomial that he thought fit the curved shape of a fern... but of course math and computing are tricky partners and even though we so often talk about explicit functions in secondary school, they really stink for computation. So when it came for me to plot smaller branching elements off of Winslow's originally proposed polynomial, sampling was a problem.

explicit polynomial sampling dead end

Thus I translated the curve into a parametric, cubic Bezier curve as I liked the idea of using the interior control points to help solve for the rotation of the smaller leaves. But even then, regularly sampling (along arc length of the curve) was not as easy as I imagined.... (there is nothing quite like 'learn by doing' and really if I were being a good academic, I should take this opportunity to read much more about this...), but I did like playing with rotations based on the interior control points.

Once I got the branching sampling and rotations to appear as I wanted, I re-wrote the code to recursively branch and draw. I'm not sure how much I will use the fern recursive growth in the final toy, but here is one example result.
Sample result of the recursive cubic Bezier fern code



And my tribute to NZ'z graphic ferns


Side track: the NZ airlines design is particularly nice, which I originally tried to copy, but of course with the recursive structure of the code, coloring all the bottom half of the leaf vs the top half of the leaf was counter the recursive structure (because there are top branchings on the bottom branchings, and vice versa) so recursion is wonderful but also restricting).

top coloring different from bottom coloring? um, no.


*references:
https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B%C3%A9zier_curves https://en.wikipedia.org/wiki/Flag_of_New_Zealand





Comments

Popular posts from this blog

growing vines and flowers

I seriously know better but I do it too...