Tag Archives: animation

Oilspill

17 Nov

Like the New York Times crossword, I’m doing the easy stuff on Monday and the tricky stuff on Fridays. Here’s a tricky one.

The Tricky ones can be CPU hogs. This sketch, based on one I did in C++ back in the 90s (before Processing) does a lot of expensive floating point calculations for each pixel, including the expensive dist(), noise(), sin(), cos() and sq(). If this were done for every single pixel shown here, it would poke along pretty slowly.

To speed things up, I’m rendering to an offscreen bitmap that is 1/2 the width and 1/2 the height. This is then doubled when it is copied onscreen. If I didn’t tell you, you probably wouldn’t notice that the pixels are doubled. A lot of websites that display large videos use the same trick; it provides a 4X speed improvement. On my MacBook Pro this gets me to about 12 – 16 frames per second, using Processing.js. In the Java version of Processing, I get about 38 fps.

In a few years, Moore’s law will allow sketches like these to go much faster. Also, this kind of sketch can blaze when accomplished using the pixel shader on your graphics card!