Ultimately, the whole point of resurrecting my old screensaver code was to finally port DPhyllotaxis to Snow Leopard.
Beyond being, perhaps, the most over-engineered screen saver ever for what ultimately draws colored dots, I wrote this as a sort of virtual flower for my then-girlfriend, now-wife-of-more-than-a-decade, Christine.
The underlying algorithm on this one is based entirely on phyllotaxis and the phyllotactic pattern of growth seen across so much of the plant world. The most well known example being the layout of seeds in a sunflower and that particular form of phyllotaxis is exactly what this screensaver mimics.
The color calculation in this particular screen saver is, frankly, goofy. Every floret — every dot — is actually rendered. The brightness is determined by calculating a color once, grabbing the red component and then calculating the color again using a slightly different algorithm and using the previous red value as the new brightness. Rather silly, but the results are pleasant enough.
When I originally wrote this in 1994-ish, it used Display PostScript to do all the drawing. Specifically:
/* this should not be done here */ PSarc(cp.x, cp.y, 15. + (11. * pp.r), 0, 360); PSgsave(); PSfill(); PSgrestore(); NXSetColor(NX_COLORBLACK); PSstroke();
I have no idea why, 15 years ago, I thought it important to note that “this should not be done here”. None. So, in the ported code, the comment is gone.
CGFloat floretDiameter = 10. + (11. * pp.r); CGFloat floretRadius = floretDiameter / 2.; NSRect floretRect = NSMakeRect(cp.x - floretRadius, cp.y - floretRadius, floretDiameter, floretDiameter); NSBezierPath *floretPath = [NSBezierPath bezierPathWithOvalInRect: floretRect]; [floretPath fill]; [[NSColor blackColor] set]; [floretPath stroke];
There are, of course, many ways to make the above a ton faster. Save for reducing power usage by going a more efficient route, it just doesn’t matter for this particular use case as I already had to slow down the animation rate considerably.
Seems there has been a bit of performance jump between the 25MHZ 68040 this was originally written on and the 2GHZ Core 2 Duo machine I used for the porting work.