Aug. 8th, 2012

jack: (Default)
What's the simplest hash function which will take an integer, and return an integer from 0 to N-1, where simple arithmetic cycles in the input don't produce visually obvious cycles in the output? Eg. if the input is 0,2,4,6,8... the output should not all be even. I assumed something simple like "multiply by blah, raise to the something power mod N" would work, but I wasn't sure.

A few caveats:

* Obviously using a non-trivial but non-cryptographic hash (eg. md5) will work, as will seeing a random number generator with the input and using the first number generated. The question is, is there a SIMPLER solution or not.

* I'm happy to contrain N to be prime >2 (or at least, odd), then the trivial hash "output = input % N" works fine.

The use case is, in a tile-based game, many floor types (grass, floorboards, etc) are not drawn with the same image in each tile, because it looks ridiculous to see regemented rows of grass with exactly the same pattern in each square, but rather using a random image from a small set of similar but different tile images.

But when I say "random", it's useful if that's determined by the tile's position, because (a) I don't have to worry about generating the values and caching them (b) each tile on the map uses the same image even if they're generated in a different order, so I don't have to keep rechecking that it looks ok (especially if I expand the concept to include more varied tiles that are still applied randomly).

This seemed like a sensible question, but I tried asking on stack overflow, hoping for "yes, just use X" or "no, I don't think you can do better than the random version", but all I got was:

* I was stupid to even consider it, I should bite the bullet and generate a random value for each tile in the map when it was loaded
* I was stupid to even consider it, I should bite the bullet and make sure I always design prime numbers of tiles whenever I'm designing the art.

OK, yeah, that will work, but once I've separated the parts of code that "draw a tile" from the parts that decide "what's the probability of each tile", I don't want mush them together again (a) wasting MY time in order to save a few cycles doing rand() and (b) meaning a trivial error in designing the art will create giant moire patterns across the whole landscape.
jack: (Default)
The internet has made advertising almost synonymous with "bad". I was watching a film trailer, and thinking that's actually an example of advertising that I often like: film trailers vary a lot in quality, but at least they:

(i) are usually shown before a film in a cinema or on a DVD, where it's easy to skip them if you don't want
(ii) tell me somthing about the product that tells me if I want to see it or not
(iii) tell me something _new_, and go away after a few months tops

And it's sort of depressing that most adverts don't do any of that, they just say "BUY COKE!" Well, duh, a business that wants to sell something, what a surprise?

On the one hand, what other examples of good advertising are there?[1]

On the other hand, if the most successful and/or parasitic companies give massive subsidies to broadcast TV, etc, maybe that's a good thing after all?[2]

[1] Should I include things like freee dropbox? To some extent, DropBox presumably just wants to make DropBox, but presumably they also want to make money from it, so to some extent the whole free version of commercial software is a big advertising stunt, but one that is (a) effective and (b) makes my life actively better, so yay :)

[2] Pointless adverts are somewhat zero-sum. Apparently you can make things _better_ for the companies by banning advertising, because they can compete with competitors less to the same effect. Maybe advertising should be legally restricted to short, informative, text-only, and let people bid to display "coke" if they really want to?

Ponies!

Aug. 8th, 2012 11:49 pm
jack: (Default)
✓ Created a Django app

It doesn't do anything yet, but it successfully writes to the database and reads from it.

It's less sophisticated than Rails in some ways, but it makes much more of an effort to explain what's going on, and provide pluggable functions and classes which make it trivial to create a website, rather than just saying "go here, type this, look it works by magic!"

I think that's partly a genuine difference in philosophy, but partly that I didn't know any Ruby before starting to play with Rails, which made things seem even more mysterious than it should have done.