Wednesday, July 20, 2016

Computer Generated Stained Glass

I wrote a  program few months ago that generates"stained glass". This came about because I was cleaning out my email and ran across a message that I had sent to myself of a flckr post by Mario Klingemann.  Mario
created these really cool images because he needed Christmas cards. I'm not sure how I found this...probably through an image search for spirals (which it's definitely not) for yet another project of mine in the thinking-about-but-haven't-done-much stage.

Mario Klingemann's "Ornaments in a Box"
More info on what Mario did is on his flickr page.

The core of his images is based on Voronoi Diagrams. So I went and found a JavaScript library (by Robert Hill I believe) and coded up a quick-and-dirty JavaScript page. Mario's algorithm seemed like a bit of a pain, so I just used polar equations with random parameters for the first go-round. The color always fades to white as the equation goes on.

Note: these images are high-resolution screen-shots from my home computer...they're quite large.





After a bit of playing around whit the random one I decided I wanted more control and actually built another JavaScript page using Knockout to code up a crude interface and to let you see the polar equations that generate the "glass" and set there parameters and colors.

Polar Equation Parameters (and  Colors)


Polar Equations Plotted

Resulting Voronoi Diagram

The user interface needs some re-factoring...it's a pain to move around and set all the parameters. Straight polar equations also don't give as nice a result. I may play around with this once a couple of other projects get done.

I do have one more "stained glass" generator, but it uses an entirely different method of laying out the pattern. So that will have to wait for another post.


No comments: