A while back I wrote this small program to create animated heightmaps using USGS elevation data, 3Delight, and GDAL.
Here’s a sample of the output:
Height Map Animation from jlarocco on Vimeo.
I have to admit it isn’t very useful, but I learned quite a bit about using libgdal, 3Delight’s C interface, and how to get data from the USGS website. And some of the animations look cool, so that’s also nice.
The source code has a few parameters to tweak the image quality at the cost of memory usage. The animation above was rendered on my laptop, so I had to decrease the quality a bit.
I mentioned a few posts back that I was learning Ruby, and that I was going to start a project with it.
That’s still true, but I got sidetracked playing with C. It sounds strange, but I was getting frustrated with Ruby’s high-level abstraction – it’s hard to tell what’s really going on sometimes.
I’ve been playing with libcurl, libxml, and PCRE. I chose those in particular because they provide functionality that I typically associate with higher level languages. In fact, many higher level languages provide wrappers around libxml and libcurl for XML parsing and web file transfer.
It was a little painful at first, but once I got used to it I’ve been having a lot of fun. I’ve spent most of my time reimplementing things I’ve previously written in Perl or Ruby, trying to match the behavior of the script as much as possible. It’s really just highlighted what I knew all along – high level languages let you focus on what you’re trying to do using fewer lines of code.
One example that really illustrates that point is a simple program that grabs posts from Twitter. The Ruby version is a mere 35 lines:
The C version is way too long to show here, coming in at 275 lines, but it’s not an entirely fair comparison. The C version is more robust, has better comments, an 18 line license, and is broken up into (somewhat) reusable functions. If I really wanted to cut the line count I could probably get it under 200 lines, but it’s never going to be as svelte as the Ruby version.
I’ll probably add some more of the code to Github in the next few days.