The Best Times to Buy Anything, All Year Round [Buying Guide]


Build a Silent, Standalone XBMC Media Center On the Cheap [Winter Upgrades]


Bacon Jam: It's Bacon You Can Spread


FontCapture Turns Your Handwriting into a Font [Handwriting]


WinToFlash Turns Your Windows Installation DVD into a USB-Based Installer [Downloads]


Google Maps Mandelbrot

As the first bit of experimentation for my masters project, I wrote a tile server for Google Maps. Basically, Maps works by downloading small (256×256px) “tiles” of the map as you drag around (this is why if you drag fast you see it appear in squares). You can use the Google Maps API to really easily overlay or entirely replace the default map with your own imagery, just by making a program which generates these small images.

As part of my project, I may be drawing images over the map, so decided to try out map tile generation to see if it is feasible. I needed an image that I could draw sections of independently of the rest of the image, and zoom in to great detail – fractals! The classic Mandelbrot set was the obvious choice, so I found a Processing example, tweaked it a bit, and wrote a Java Servlet which used Processing as a back-end to draw the map tiles. This worked incredibly well (after dealing with some issues with Processing not being thread-safe), and within an hour or two of conception had a fully working version. I showed this off in my tutor meeting, but due to my rubbish home broadband it was taking upwards of a minute to load a screenful.

I then decided to “grow up” the implementation, rewriting it in PHP and putting it on this site. Initially this worked fine (after adding caching for the tiles) but very quickly brought the server to a standstill, as fractals are pretty hefty calculations, and one person visiting the site would request ~30 of them just by going to the web page. I adapted some optimised code from The Computer Language Benchmarks Game but this didn’t help much, as the code wasn’t too bad already!

My next idea was to pre-generate all the tiles on my machine, and upload these to the web host – this way, the web server would only need to generate tiles if the user zoomed in too far. I hacked the servlet into a standalone app; removing Processing and instead using the javax.imageio classes to directly write PNGs, using 4 threads and pumping out tiles as fast as possible. I left this running for a couple days, creating about 25GB of tiles, uploading them to the web server as I went along.

I played with this new ultra-snappy version for a while, but realised that the interesting part of fractals is the ability to zoom in to infinite detail – panning around is all well and good but as soon as you zoomed too far the server went horribly slow again. At this point, I only really had one option left – rewrite the tile generation in C. I ported over the Java code to calculate the fractal, and used libpng to write out the images. Surprisingly quickly I had a C version (I didn’t bother with threading as this is a headache in C), which, after a bit of benchmarking, turned out to be massively faster than both the Java and PHP versions. Before people jump on that as “LOL JAVA IS SLOW!!1”, the language benchmarks I took the code from show Java as only slightly slower than C – I think the bottleneck was in fact in writing out the PNG, as I was (accidentally) using the OpenJDK implementation which is not known for its speed!

Anyway, with this new C version I started pre-generating tiles at lightening speed, when on a hunch decided to change the PHP code to simply run the C executable to generate the tiles. Trying it out, I was amazed. I even had to do a quick check to make sure it wasn’t still serving cached tiles and was in fact generating them on-the-fly.

So there you have it! I’ve just realised I’ve written that huge essay and not provided a link to the hyper-optimized, super-fast, Google Maps Mandelbrot!

Source code to all of this available on request; I plan to tidy it up and release it on here some time soon as well.

Comment


Lumin

Lumin was to be our third Android app. We both had the idea independently and started coding – it wasn’t until we both asked each other’s help that we realised we were both making the same app!
We ended up blending James’ UI with my audio engine. The idea was a simple step sequencer, where the user could light up squares to set a pattern of notes to play, accompanied by some beautiful samples I created using non-traditional scales. This was the first app that I spent any serious time doing graphics for – I’ve started to learn Illustrator as a result.

This was to be our first paid app, but we couldn’t bring ourselves to release it as we found no way of making it stable – the phone just can’t handle playing samples and keeping time accurately enough for it to be fun. I felt that if people would be paying for a sequencer, it should at least be able to keep time!

This one is on the backburner until Android’s sound support improves – but at that point there’s a paid app ready to go!

Comment


Home Toggle

This is the second app by James and myself. It’s a one-click settings toggler, allowing you to quickly change phone settings like silent mode, wifi on/off, with one press on the desktop.
Most of the credit goes to James on this one – he dived straight into the (shaky!) widget framework released as part of Cupcake, managing to hack something together really quickly. We soon discovered that Google had quietly disabled the interaction with most settings, saying that they were being “abused” by some applications. Surely this is what the whole permissions framework is there for in the first place? If I grant an application permission to change my settings, then I’d expect it to be able to do exactly that! Now, however, the best you can do is link to the settings page, for the user to do it themselves. Still, we felt that the app was useful, as some settings were left “unsecured”, and others it was nice to have an on-screen status.

We’ve had over 3000 downloads to date, which is a pretty big accomplishment for a small app! James and I are both excited to see what’ll happen once Android becomes a more mainstream OS and hence the market gets bigger.

Comment


Two Months Without Updates

Oops, blogs are meant to happen as you go along! I’ve been snowed under with work (as anyone who’s spoken to me in the last while would know!) but I’m starting to get things in order.

I’ve been doing some interesting stuff with James Grafton on Android, published another app and have a couple in the pipeline. Work on my Masters project has also kicked off so I’ll be posting about that in a sec too – just some little experiments and things for reference.

Anyway, I’m still alive, and I’ll make a mental note to post here more!

Comment


Get Me Home

Over the past couple of days, James Grafton and I have hacked together an app for Android to get routes around London, using results provided (scraped) from TfL’s site.

We’ve done it mostly as an experiment into building a simple Android app, and I think we’ve come out with something pretty useful! It’s got a couple of neat features like guessing your current location, and providing a default destination (such as Home). It’s a pity the TfL site itself is so slow – especially over mobile internet!

Comment


« Older