Ambient light controller

22 Apr 2013

A while ago I saw amBX online, a lighting system for your computer that changes colours depending what is on screen. Kind of cool but not really necessary. However, after receiving my Phillips Hue lights, I wondered if I could hack together the same thing.

My lamp is placed behind my monitor

So I did, and it was surprisingly easy - less than 80 lines of code! Here’s the general idea:

Five times a second:

  • Get the average colour on-screen.
    • For performance reasons, I only looked at a pixel every 8 across and 8 down, so… I think that’s 1/64th of the total pixels.
    • For average colour I just added up all the RGB values and divided them by total pixels.
  • Get the average brightness
    • I calculated average brightness by taking the final value, adding up R+G+B and dividing by three.
  • Convert the colour from RGB to the Hue’s XY colour space
    • Tricky, until I found Phillips’ page on this. There’s some matrix multiplication I guess, but I just followed their formulas.
  • Set the specified light to the average colour and brightness.

It’s a little awkward to use right now but works pretty well as a proof of concept. I’d like to make the transitions a little smoother, and work out exactly how fast I can trigger this to occur. Preferably I’d have the light go out when the computer shuts off, too - but that might be better as a separate script I think. We’ll see.

In the mean time, check it out on Github if you’d like:


Yesterday I attended my second gamejam, an eight hour event where teams form to work on small games together around some loose themes, which this time were Black & White, Rockets, and Masks. Read More...
It's early to say this, and maybe a little crazy, but I can't help but put Twenty, a simple game from Stephen French, in the same category as Tetris. Not just in the way it plays - though it shares that methodical feeling of clearing a space that transitions to crowded panic - but in how it takes just a single mechanic and a simple interface to create something truly elegant and timeless. Twenty deserves to be played for decades to come, just like Tetris. Read More...
![Trippy!](/assets/snake.png) Phantogram always puts on a great concert and at the last one I was struck by a black and white animated backdrop of concentric circles giving the illusion of a slithering snake. As a challenge I decided to see if I could recreate this effect in a web browser. After starting out with Snap.svg I realised I could probably do the whole thing in CSS. Read More...