Keets
The chickens were “gifted back to nature” last Winter. No egg production and a new baby in the house brought this shortcut we didn’t like taking.
I’ve updated the list of traditions and cultural artifacts I understood since moving to Vermont for the occasion. It made me understand how so many religions have the concept of sacrificing animals to deities, and the idea of offerings to gods in general. I heard the coyotes come from the next hill over the same night and rejoice at the bounty. I never had issues with coyotes, coincidence? I think not. Everything happening at night feels supernatural. It’s not the first time we take animals deep into the forest to be cleaned up, and this was likely a frequent occurrence in the lives of humans when religions popped up.
We’re populating the coop this time with Guinea Hens. Apparently they’re like guard dogs, but they also eat ticks, and snakes, and they require little feeding.
An HTML5 canvas Flood Fill that doesn’t kill the browser
I took the longest time implementing the fill tool
on Mandalagaba. How hard could it be? Recurse through pixels looking for a color and update them to a new color.
While this method certainly works and is easy to implement, it is also extremely slow. Slow in a way that hangs the browser, yielding infamous messages from the browser.
Here we’ll take a look at various Javascript flood fill implementations along with their drawbacks. Jump to #4 if you are only interested in the best one.
2018-10-04 – edit – added fill algorithm #5 which proposes an alternate approach to filling pixel by pixel. Depending on your project it may or may not serve your needs better.
In all cases, the code is available in the example iframe, look for the function flood_fill.
1. Simple Recursive
Not much to explain here, we simply recursively call the function on adjacent pixels when they match the color we are trying to fill over.
Click to change color / pop-out link
It’s reasonably fast but the problem with this one is that any fill area slightly large yields too much recursion which breaks subsequent JS. This Canvas box is 200x200px and at 300x300px, Firefox complained about:
It’s easy to see how this implementation will not satisfy a reasonably featured paint program. Even if your browser let you stack more function on the heap, I would bet it would lead to slowness.
2. Iterative
We simply take the previous idea of looking at adjacent pixels and filling them, and make it iterative instead so the function calls don’t get stacked to a ceiling.
Click to change color / pop-out link
The problem with this is is that is is sloooow. So slow it stalls browser. Most of time is spent having to keep track of pixels_stack. Recursion doesn’t have that need but as we’ve seen, it has other issues.
3. Recursive-Iterative (AKA catch-your-breath iterative)
This is a twist on #2 which every so often, recurses on itself via a setTimeout to let the browser catch it breath a little. It also yields a cool visual effect.
Click to change color / pop-out link
I really like the visual effect, and it makes the slowness tolerable. But the issue is that Mandalagaba has a network engine and allows for re-rendering of one’s work. So synchronization is a big deal, and you know what makes synchronization easy? Not having to worry about it.
So as long as I can help it, my life is a lot easier if the operations the users can perform are atomic. Operations need to be able to be processed one after the other counting on the fact that the ones that came before have completed.
The first 2 solutions are atomic but suck; this 3rd one, however cool it may be, isn’t.
4. The Holy Grail
I’m not sure where this algorithm originated from, but I’ve gotten to know it on this web page which explains it very well (with GIFs!). It is iterative and goes about finding pixels to fill in a much smarter way.
Click to change color / pop-out link
That’s it, no drawback here 🙂 I’ve tested it on large canvasses and this is what is implemented on Mandalagaba. Now of course, in a real application there is a ton more complexity dealing with smoothing edges and blending alpha. I only wanted to expose boiled down versions of these algorithms so they are easier to wrap your mind around.
5. The Holier Grail?
While #4 is fastest algorithm for filling pixel by pixel, I found myself in the need to have a fill operation in for form of a path which is filled with the native HTML5 canvas capabilities. This algorithm is a bit different from all the other ones in that it doesn’t go through every pixel and fills it. What it does is pathfinding to draw the outline of the shape of be filled, and then simply calls the native canvas fill() function. It does come with certain drawbacks and so I wouldn’t recommend it unless you specifically need this sort of approach.
Click to change color / pop-out link
Feel free to ask questions in the comments.
Haying Fever
I’m getting good at changing implements
[mejsvideo mp4=”http://ben.akrin.com/videos/haying_fever.mov.mp4″ ogg=”http://ben.akrin.com/videos/haying_fever.mov.ogv” webm=”http://ben.akrin.com/videos/haying_fever.mov.webm” poster=”http://ben.akrin.com/videos/haying_fever.mov.jpg” width=”640″ height=”360″]
A nightmare if you’re allergic to pollen

Stuck in the mud once more… The truck will pull it out.
Take 2, with board to help not sink in. We need more culverts.
Off we go! later suckers, me & my tractor have got some fields to mow.
Black gold
Room flooring
This is a bedroom a kid will grow up and become a teenager in, I laid tongue and groove pine because I could use the hardest of woods, there will be holes through it. I figured it’ll be easier to be ok with the damage if it’s not super expensive wood. The result looks great but it will wear faster. I love the angles in that room, Robin has not been in it for weeks, we’re keeping it a surprise and will have a ribbon cutting ceremony in a couple of days.
A first in 3 years
A nicely finished room, no visible insulation, studs or vapor barrier. It is incredibly satisfying to work on finishing a room. Since we now have enough space in the house, all the others will follow. We are done making temporary arrangements.
A guide for the circular is incredibly useful for making rip cuts.
Finer work is super satisfying
I opened the windows and discovered the view a few weeks ago, giving them a nice frame makes it all the more enjoyable.
Nosy Monster alive and well
The Nosy Monster has been sitting on my desk idle for a while now, I’ve always wanted to work on it a bit and make it more reactive to web input. Finally, I bit the bullet and it’s now a lot smoother to operate. Instead of clicking for pre-timed commands, the start of a key press actuates and the end stops. With a websocket communication layer and a socket python command server, the commands find their way from keyboard to motors super fast.
To account for wireless imperfections and AP hopping, I also wrote the logic such that there isn’t a “start” and a “stop” command. Instead there is only a “start” command which gets sent every 200ms and if it isn’t heard every 300ms, Nosy Monster stops. This ensures it won’t be locked in a state of actuation which could lead to perilous situations.
I intend on polishing the code & publish a tutorial that hopefully a 7 year old could handle.
The Nosy Monster was deployed at the Dartmouth Thayer School of Engineering’s open house. I didn’t know how robust it was going to be under sustained kid use.
It turned out to be a huge hit, I let the kids drive it around a bit and then I’d throw the Nosy Monster in another room where they would have to find their way around with no visibility other than the camera. It performed flawlessly through the evening.
It’s always an enormous point of satisfaction to see kids get into something you made. Once I sent the RC car “to Mars” (the other room), the kids were really focused. All but one got stuck and never came home. I should have had a prize for the one, but what’s next, participation trophies?
With a much more usable and reliable toy, I decided to setup the same kind of maze in a house room under construction.
I moved the camera up on a stick for a better angle of vision, the next model will have a fisheye camera.
Without a reverse, it takes a few tries to get through the maze without getting stuck. He had to learn to be careful.
I’m bubbling up with ideas of cool things to do with the concept and acquired techniques. From a solar powered exterior land rover, to battle bots.
Oddly fascinated by the leaves
We’ve been watching an excellent crowdfunded documentary series called Woodlanders. It brought to our attention a guy working to reintroduce the chestnut tree to American forests. We couldn’t believe it was even possible to acquire young chestnuts so we pretty much had to place an order. It arrived this week and to our surprise it still had leaves from the season previous. This is when it hit us what it meant to be planting this.
Solar monitoring back online
The solar instrumentation has been lacking for a couple of months since the solar panels’ current sensor blew up. It took 2 months because there has been a lot mistakes and learning along the way. It should have been simple, replace the 30A sensor by a 100A one right?
Well it wasn’t. First I ordered the wrong 100A sensor, meant for AC use. Then I had a myriad of issues around calibration.
- at the 5V input port, a 0V reading didn’t translate to 0A, this sensor goes from -100A to 100A so it is 2.5V which translate to 0A.
- with the skew from miscalibration, the value I was getting made no sense for what I know the panels can make
- orientation matters as again, this sensor can read negative values
- a cloudy day makes fluctuations hard to detect
- moving the sensor from one interface kit to another after calibration resulted in another skew.
All these little things I could have picked on their own, but together they conspired to make me thoroughly confused and left me seeking support from the Phidgets forums. I was once more impressed by Phidgets, the help I got was fast and efficient. Phidgets are more expensive but I was proven once more that they are worth every penny. They have many other advantages, I have nothing but good things to say about them.
Calibration, I really need to tidy things up in there
I’ve learned a LOT of lessons with this one. Not the least of which is to be ok with the imperfections of analog data. I’m a discrete data type of guy, it doesn’t come naturally to accept skews & variations.


































