I was doing some SDL stuff for work and wrote a little wrapper around SDL to make it a bit easier to use. SDL's blit() function wants four arguments, two of which want four more arguments. Really all it needs for the common case is the image to blit and the x, y coordinates to blit it to, called as a method in the target image.
I wrote this app for my own use. I wanted to be able to visualize where the buses were (or rather, where they're supposed to be) when I'm standing at a corner. That way, if I'm going north-west, for example, I know whether to expect a west bound bus first or a north bound bus, or whether I should just start walking. The bus system in Phoenix isn't great. A lot of the time, you'll get there sooner if you just walk a few miles. A previous post talks more about this. Short version is, I have an SDL based app that has a scrollable map with an adjustable "current time", that shows where all the buses are supposed to be at that time. I scraped their website and did my own geocoding. Bus locations are interpolated between stops on the time table.
Having that for myself, the next step was sharing it, and that meant Web, or possibly, an iPhone app or the like.
Turns out that it was easy to retarget it to the web, just by replacing my SDL wrapper. Rather than using SDL, it uses GD. I had to rework the original and the other wrapper a bit but the program is basically agnostic about which it works under.
The window gets output to the browser as one big inline, base64 encoded image with the ismap attribute set. You may have forgotten about this attribute. When an image is inside an anchor (a) tag, ismap causes the x, y location of the click on the image to be added to the URL in the a href.
Eg:
my $get_string = $request->request->url->as_string;
if($get_string and $get_string =~ m/\?\d+,\d/) { $graphics->hit($get_string =~ m/\?(\d+),(\d+)/) or $draw_playfield->(); } else { $draw_playfield->(); }
my $png = encode_base64($app->png, '');
$request->print(qq{ }); $request->next;
I know you're doing your own thing, that's cool, but maybe it'd be simpler as a google map app? (If possible.) I guess the problem would be updating the data.
What you're doing reminded me incidentally of using Processing. It's possible to export as either a Java app or as an applet for a browser. (The main problems for me with Processing are: 1) it's Java-based, 2) the IDE seems buggy in Linux (at least I had problems sketches, as it would freeze the IDE).)
Re:google map, Processing
scrottie on 2009-03-16T03:59:25
Yeah, this should have been a Google Maps app. I looked at the API briefly but felt bogged down. Also, I don't have GPRS/EDGE any more, so I wanted something that worked off-line with the on-line version being an after thought. I have played with Processing a bit. Where I got stuck with it was CPU usage and the Flash-like fps thing, where it tries to draw so many frames per second regardless of whether anything has changed on the screen. It had some threads that were very CPU hungry that I really didn't know what were doing. I was trying to re-build the MUD GUI in that. I should have stuck to the raw Java.
But this is kind of an off-shoot of work, too. I'm trying to find and learn some Perl graphical toolkit that doesn't suck donkey dong. SDL is like a chose your own adventure where every pathway leads to coredump and I've wasted too much time navigating its various corridors already. There's Ogre, a wrapper around the open source ogre engine, and PDL::Graphics::X, which lets you use raw PDL arrays as graphic buffers. I need to refresh my memory, but slices in SDL should work fine as a blitter operation. I need to figure out if there's something that would do alpha masking and blending.
I have to admit that I've been pondering how to go about doing a Processing-like thing in Perl. There are quite a few things like Processing but they all seem to suffer from the wrong amounts of complexity in the wrong places, including too little complexity where there should be more. They kind of suffer from the MVC framework problem, where it's really easy to get something up, but really hard to finish it, until you've learned your way around it well.
Wow, I didn't think it was possible, but they made use.perl.org suck even more. I'm afraid this might be my last post here...
-scott