You’re visiting the personal website of Joost Schuttelaar.

Take a look


You can e-mail me at jelephants @ jstsch.com (anti-spam: please remove the mammal with the big snout).

Twitter feed @jstsch

Sorry, feed is gone. API has been killed by Twitter.

Old-skool fire demo effect in Javascript/Canvas

Saturday April 5 2014

For fun and to experiment a bit with RequestAnimationFrame I reimplemented one of the classic demo effects using Javascript and the Canvas element.

[open fire effect full-screen in a new window]

The code and algorithm is based on the fire example in The Demo Effects Collection, originally in C (source). The algorithm is pretty simple: randomly pixels are turned on/off in the bottom row. Each row is then shifted up, blurred with the next row (from the previous frame), decayed and color mapped.

At 30FPS it takes about 17% CPU in Safari on my mid-2010 MacBook Pro 17”. Quite a bit for something that used to run on machines a thousand times less powerful, but of course this would’ve been implemented in assembly back then instead of Javascript :)

The flame intensity randomizes by default. You can set it manually using 1…9 on your keyboard (and 0 to go back to random mode). You can also tweak the rendering resolution by resizing the canvas element. The FPS can also be modified by altering the source.

Simple trick to revive NiMH AA batteries

Saturday March 8 2014

Revive setup for NiMH AA batteriesTL;DR: use a regular alkaline AA battery to give your NiMH cell a boost for a little while — it will pull it over its dead zone.

In my Wii controllers I had a bunch of rechargeable AA-batteries sitting unused for more than a year. Completely empty of course, and most of them wouldn’t charge at all anymore. My charger just blinked in error, and two of them didn’t even register at all. Multimeter to the rescue, and of course their voltages were extremely low, some even under 100 millivolts. What a waste!

Continue reading Simple trick to revive NiMH AA batteries

PHP snippet: Deprecate a function

Friday July 12 2013

Sometimes you want to remove an outdated function, but can’t because users are relying on it. Then you’ll have to deprecate it instead. The snippet below logs a useful warning, which shows you where the deprecated function is used (without bugging the user):

 * Function to log a deprecated warning in the error log.
 * @param string $hint Also log a hint how to fix this deprecation error.
 * @return void
function log_deprecated_warning($hint = '') {
	$trace = debug_backtrace();
	$caller = (isset($trace[1])) ? $trace[1] : reset($trace);
	$hint = (empty($hint)) ? '' : '. '.$hint;
	error_log('Warning: Call to deprecated function '.$caller['function'].'() in '.$caller['file'].' on line '.$caller['line'].$hint);

Usage example:

function some_old_function() {
	log_deprecated_warning('We've replaced this with the new shiny banana method.');