Cicadients
Published 12 years, 5 months pastI’ve been a fan of “The Cicada Principle” since it was first published. After wandering through a CSS gradients gallery or two back in April, it occurred to me that it ought to be simple to merge the two things. So I did: thus was born “Cicadients”. It took me until now to actually blog about it because, well, you know, things were, hey, what’s that weird thing over there?
What?
As a recap, the Cicada Principle states that if you pick a few simple patterns that repeat at prime-number intervals, you can create complicated patterns that only repeat at intervals that are the product of the individual intervals. For example, if you have patterns that repeat every 3, 5, and 7 pixels (respectively), the combination of the three will repeat every 3×5×7 pixels, which is to say every 105 pixels. Bump up the intervals, and you get some truly staggering numbers. For example, shift up to 7, 11, and 13 pixels and their combination repeat every 1,001 pixels; combining 11, 13, and 17 gets you 2,431; combining 13, 17, and 23 yields 5,083.
The examples presented in the original article use semi-opaque PNGs to achieve this effect. All I did was replace their images with images of my own; to wit, CSS gradients. (Yes, gradients are images, every bit as much as any PNG. They’re just described differently.) In doing so, I not only reduced server hits, but I also saved a fair number of bytes. In the first case, I did so while achieving pixel-perfect fidelity to the original. In the second case, I didn’t make it exactly the same as the original, but I got fairly close in 0.63KB (2.81KB with prefixes). I could probably get closer to the original with a little more effort — a couple of my gradients are a little too smeary — but that will probably wait a while, if I ever get to it at all. But, again, the final result is a kilobyte or two; the original example was 23KB plus extra server hits.
That was the real reason for my efforts, aside from the simple pleasure of doing it: to find out how much more efficient a gradient could be than a raster image in appropriate situations. I had expected some savings with gradients, but I was frankly astounded by how much was saved. You can do a lot more with gradients than sunset backgrounds and lickable button highlights.
Of course, gradients are not right for every situation: the third example in “The Cicada Principle”, for example, should only be done with gradients as an example of how not to do it. Possibly also as a public declaration of deep masochistic tendencies. Either way, you’d probably crash browsers, and that’s currently the job of radial gradients.
I’ll be very interested to see if people come up with their own cicadient examples. If you do, let us know about them in the comments!