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.


Weeding & Gate Design

So I got up early this morning to weed out a couple of beds in the garden and to write blog posts. I'm trying to get up early at least one day a week to stay on top of all of the flower beds and garden.

 
Scraggly Corn
I weeded the bed in front of the peas..and yes this corn is pretty scraggly. It got (mostly) dug up and replanted twice when it was only a couple of inches tall. I think either the crows or a baby bunny that I chased out of the garden dug it up and ate it.

I built a new garden gate earlier this year, but I still haven't put a sign on it yet. The old gate had a "Weed 'em and Reap" sign that I carved. I think it's time for a new saying, but I haven't come up with one yet.
Old Gate

New Gate

Saturday, July 2, 2016

Teaching a Computer to Paint

One of the (too many) things I do is manage the website for the Westerville Community Bands (www.westervillebands.org).  I needed a "summer" themed background picture for the site. I had a nice photo of the band playing at the Alumn Creek Amphitheater in Westerville, but it was a bit too busy for a background. I wanted something more abstract.

So I wrote a quick-and-dirty program to "paint" a picture by drawing a 45 degree stroke up and to the left. It worked by choosing the pixel under the current location and moving up one and over one until the pixel wasn't "close enough" in color to the original color or we were at the edge of the picture. Then it would draw a line from the start location to the end location using the original color. Repeat ad nauseam. Of course the original algorithm had a math error that caused strokes to get too long the further right you got in the picture...but I did figure that out eventually.

For the last year or so I've been playing around with the algorithm in between other activities. Below are some images of the results.  

NOTE: you'll need to view these full-size on a fairly big screen. They look pretty much like regular photographs when they're shrunk down.

Except for this one...I had the "abstraction" level cranked up pretty high.
Olivia Wilde

The current version is based on seed fill regions - the "paint bucket" tool in most graphics applications.

The basic outline of the code is:
  •  Do a 3x3 "blur" operation on the image to smooth out any noise and coincidentally smooth out the edges of regions.
  • Check points every 10 pixels (or so) and see if the colors around that point are pretty close  to each other and that it's not part of a seed fill region. If so then start a seed fill region.
  • Go back through every point on the image and if it's not part of a seed fill region start a seed fill region there.
  • Merge any regions that are smaller than some size (usually between 5 - 25 pixels) with the neighboring region that has the closest average color until all regions are above the minimum size.
  • Go back through the image merging adjacent regions who's average color is "close enough" to each other. Continue to do this until no more regions are merged.
  • Figure out the slope of each region. For wide regions use the top edge or bottom edge; whichever one is not horizontal. For tall regions use the left edge unless it's vertical.
  •  Create a stroke for every line segment that intersects the region by going down and across. Pick the median color of the points that intersect the region from the original image, not the blurred image. The median color is used to minimize getting a streak of the wrong color across the image.
  • Create the output canvas. 
  • Fill the regions with the average region color, possibly passed through a color transforming function. The filling is used because I'm using anti-aliased line drawing and with a white background you get a lot of streaks. I have also just painted everything twice, but filling works a bit better.
  • Draw the strokes on the canvas, possibly passed through a color transforming function.
Of course there was a lot of playing around to figure out what worked. There was a lot of code that got thrown away because it didn't work or the time it took to run didn't make an appreciable difference in the output.

Mountains in the Fall


And once again I learned that you really need to profile the code before optimizing. A couple of "optimizations" that I made, really slowed down the processing.

I also added the ability to manipulate the output colors, though none of these pictures are using it.

Asters in the Garden
Now all I have to do is build the robot to actually paint the picture....of course they do make them; they're called ink-jet printers...
Mountain Scene

Neuschwanstein Castle












Friday, July 1, 2011

House Design

It seems that about every year or so I start designing houses. Recently it's because I don't really like the house I currently have; it's too expensive to heat and cool and it's a boring ranch house.

If I were to build a new house, I would probably go with a Victorian inspired straw-bale construction house. Straw bale because for about the same price per square foot of a "normal" balloon frame house you can build a super-insulated house. Victorian style because they are so much more interesting than the cookie cutter houses of today.

Here is a video of two of this year's house design crop. And yep the first house is complete crap and the second has the worlds most needlessly complex roof. I guess I'll be sticking with software and not real-world architecture for the foreseeable future.





This is my first video production, and yes I know you can tell that. The music in the background is the first 40 seconds or so of my prime melody described in an earlier post.



Here are some pictures of some of the rest of this particular crop.








I may not have come up with a great house design yet, but I did get a lot more proficient with Sketch Up.

I also did a lot of thinking about why we formally design things instead of just diving right in.

Only two reasons that I can think of:

- The design must understood by someone else. Either because they will be involved in making it or they need to understand what will be built in order to approve it.

- It's less expensive to change the design than to change the object being built.

Tuesday, January 25, 2011

Nuts!


As my reader keeps reminding me, I haven't done an update for a while.

So I'll start with a random update I though of back a couple of months ago..........

If you'll remember back last year a bunch of the "we-are-all-going-to-die-because-of-global-warming" crowd was proclaiming immanent disaster because there seemed to be a lack of acorns on the oak trees.

To them I have but one word: NUTS!

Gallons and gallons and gallons and gallons of nuts. Acorns to be more specific. Pin Oak acorns to be more precise. About 14 gallons on this particular cleaning of the patio.

These are shots from 28-0ct-2010 of my patio. This was the second time I'd cleaned it off. I had to clean it off a third time and got even more acorns.

I only bothered to clean off the patio because I was hauling and stacking firewood and had to walk across the patio. I learned when I first moved in that walking on a layer of Pin Oak acorns over brick is pretty close to walking on a layer of marbles over brick...with pretty predictable results.


Oh, and for all you global-warming fans:
  • We know a lot less than we think we know; especially about how climate works.
  • Mass hysteria that turns out to be nothing discredits the proclaimers (e.g. the boy who cried wolf)
  • Water is more of a greenhouse gas than CO2 is; but it's pretty hard to convince Joe Average that water is a threat.
  • Without the CO2 scare Al Gore would be known for what he really is: a failed politician.

Sunday, May 9, 2010

Pedals, Plumbing, Pucks and Pickets

So, as my friend Todd keeps mentioning it's been a while since I've updated this.

I started at least two, if not more, updates but never quite seemed to get enough of them done to bother publishing.

Today I've been working on brackets to replace the pieces of plywood on the big arbor/trellis I built my Mom last year. Gaps are opening up at the bottom of the joints between the sections. I'm guessing that the force of the arch is pushing the posts out allowing the joint to open up. It's not really a structural problem; my nephew was doing chin-ups on one of the cross braces at Easter and he's pretty good sized. I'd guess he weighs around 180 pounds. But it looks bad and it might be a problem in a few years.

To make the brackets I'm cutting a pattern out of 1/16th thick steel plate with a jigsaw for the ones on the outside faces. The ones on the inside of the trellis will be steel strap that has holes every 3/4 of an inch. It's about an inch and a half wide. The entire bracket is a bit over 8 inches long. It's six inches from center of the hole to the center of the other hole.

The black/blue color is from tempering them with a hand-held MAP gas torch (like a propane torch, but a bit hotter). I glued a paper template on them to show where to drill/cut and using the torch was easier than trying to sand off all of the paper. And I like playing with fire.

After I cut them out and filed/ground (most) of the oopses and rough edges off I took a ball-peen hammer and hammered the back of the bracket to make a convex front. It also makes them curve the long way, but a couple of smacks with a rubber mallet flattens them back out. The curve adds both strength and texture to hide the imperfections. (Or at least a little bit of the imperfections).

I finally started riding my bicycle to work. It's about 6 miles one-way. Rode Tuesday through Friday last week but I'm probably going to wimp out tomorrow as the temperature forecast is 35F in the morning. That wouldn't be so bad, but I have a down-hill about 1/4 mile from my house and that's pretty cold when you add a 30 MPH wind-chill on top of it. I've also a part of a program to finish writing before I can leave work tomorrow; so I might be staying a wee bit late. (No headlight on the bicycle.)

Two weekends ago I got the lovely task of replacing a septic line (hence the Plumbing in the title.) I had rescue rooter come out, but they couldn't get the snake to go all the way through. I was pretty sure that it was tree roots in the line. And it was, but the line was also slightly smashed. Which is what let the tree roots in in the first place.

The line sits directly on the gas-main for my road. They didn't fill under the septic line where it went over the gas main and smashed the septic line when they back-filled. The smashed part was too narrow for the head on the snake. So I got to dig it all up (by hand) and replace it and back fill. Luckily it wasn't too far down and a bit less than 25 feet. (I've hand dug about 535 feet of drainage tile on my property so far...I've a60 foot (or so) ditch open right now that I should finish.)

The night before I started digging septic lines was the final playoff for the Hockey team I play on. We finally made it to the finals. The last time we made it that far was nine years ago. I had a good game, but unfortunately the rest of the team didn't.

I also finally got the picket fence I started last year cut out, put together, stained and put in place. The jig I used to make it looked pretty cool. Something about all the repeated elements. The fence has been up since March.

Saturday, December 5, 2009

Behind Again....

Well I'm really behind in posting again.

So I survived the Hilly Hundred. Had to walk part of 2 hills both days, but not bad for only riding about 12 times this year.

Up until Thanksgiving I spent a lot of time dealing with leaves. What I like to do is run them all through the chipper/shredder to grind them up really fine so that they don't blow all over the yard and they decompose faster. I use them in the flowerbeds and in the garden as mulch. Of course this entailed fixing the chipper/shredder first. (I broke it earlier in the year.)

Last year I just built a "box" out of straw bales to catch them as they exited the shredder. I then raked them into a garbage can and dumped them into the shredder. I did that for about two garbage cans full this year and decided it was too much of a pain.

So I built a ramp out of 2x12s and a mostly straw-bail box. I thought I would have to stand on the ramp and rake the leaves up into the shredder. This turned out to be unnecessary and it was still a bit of a pain emptying the "box". It also wasn't very mobile so I ended up moving a lot of leaves a fairly long distance to shred them.

The next go-round I build a light(er) weight ramp and built a box on top of my small trailer. This worked pretty well after a few tweaks to allow air-flow through the trailer. This was much more mobile, so I spent less time raking leaves long distances. Unfortunately I broke the chipper/shredder again. Luckily I was mostly done. The last few batches of leaves just got put directly in the garden.

I hosted Thanksgiving for my family for the third year in a row. I cooked turkey, stuffing and mashed potatoes for 11. They bring side dishes and I usually con my mom into making the gravy. Nothing got burnt. Nothing was under-cooked and nobody got sick so it must have been a success.