Node’s not available in the standard Wheezy repositories; but you can get it from wheezy-backports; this guide covers installation including npm.
No idea how well npm will integrate with apt; I guess i’m going to find out.
Node’s not available in the standard Wheezy repositories; but you can get it from wheezy-backports; this guide covers installation including npm.
No idea how well npm will integrate with apt; I guess i’m going to find out.
How wrong could I be?
The simplest way to do this is get hold of a bitmap with the regions we want coloured in with just one plain colour. When you click the screen; check the value at that point in the bitmap; and use that value as a key into your list of countries.
Uhh, no; maybe in the 90s. Nowadays in a modern browser; the easiest way is to use an SVG image, with the D3 library. Then we can use jquery style CSS selectors to add click handlers to relevant paths; and on a click event modify its attributes to change the fill colour. D3 also gives us panning and zooming functionality.
Anyway i’ve updated my little project – it’s no longer canvas; I just use an SVG image and the render loop has gone.
There is a small problem – it doesn’t work on my iPad. Debugging will have to wait for another day i’m afraid; perhaps after i’ve added a few more fun bits to it.
Edit: This project has been updated. To view the code referred to here; you’ll need to look at an earlier revision.
I love Warlight. It’s a dangerous obsession for me. The game is basically multiplayer Risk, with a lot of different possible maps; and a few other additions as well. Risk is super simple though. Surely we can write a Risk game in HTML5 Canvas?
Let’s have a quick sketch of the bare minimum features for a complete game:
Well, suddenly it seems pretty daunting. And I am definitely distracted by flood filling. For some reason, i’d love to have a go at flood filling. I’d like to fill it slowly, so you can watch it happen. I can’t stop thinking about Warlight, and flood filling. So now i’ve got two obsessions.
To motivate myself through this project, while maintaining two obsessions; I need to break it down a bit. A good starting goal is an app that allows you to click on a map and tell you some bit of information relating to where you clicked. Talk about a bite-sized chunk; it’s totally trivial. It also solves item #1 on our list above.
The simplest way to do this is get hold of a bitmap with the regions we want coloured in with just one plain colour.(1) When you click the screen; check the value at that point in the bitmap; and use that value as a key into your list of countries. This doesn’t have to be the bitmap we render to the screen – we could use a totally different image; perhaps with more colours or textures. To keep it simple though, let’s use the same image. We’ll make a note of this as a “want” for later though.
So what image? We need some assets for this – I mean that’s another whole obsession isn’t it. We could spend ages trying to find the perfect map. Or, just use a coloured continent map from Wikipedia. Boring, not very attractive, but does the job. A bit like my car. It does immediately bring up a problem though; what do we do if the image doesn’t fit in the viewport?
Let’s do nothing for now – after all, i’m a shipper, not a perfectionist – and just make a note of that in our list of “wants”; which is now complete:
Other than that; job’s a good’un. The usual caveat with regards to code quality applies of course. It’s the first iteration! We’ll refactor later… There are another couple of interesting points which come out of this prototype:
[1] Another way to do this would be to use some geographic data (for example GADM data sources) to both render the map and do the hit detection… A fun project all in itself.