Question

What is a suitable algorithm that can be used to generate random, but likely humanly distinguishable, graphic square icons?

Icons, from 57x57 up to 1024 square, such as used for mobile apps, preferably using something like Core Graphics commands/operations? (or an equivalent)

I tried filling square bitmaps with rand(), but they all look like mud, very hard to distinguish between by sight.

Was it helpful?

Solution

Identicon

Random icon you are talking about is an Identicon.

Identicons are icons that are generated from some form of user information.

An Identicon is a visual representation of a hash value, usually of an IP address, that serves to identify a user of a computer system as a form of avatar while protecting the users' privacy. The original Identicon was a 9-block graphic, and the representation has been extended to other graphic forms by third parties. – Wikipedia

Sample Implementation

You can have a look at:

  • NIdenticon - a C# library that helps creating simple Identicons. Examine IdenticonGenerator class that has only one method called Create(). You should be able to extract the algorithm/general idea from it.

  • Contact-Identicons source - Android app source code. The app generated Identicons. This blog post includes a sample of Java code used to generate a 5*5 pixel, horizontally symmetrical identicon much like the ones github uses.

  • IGIdenticon source - Objective-C identicon generator. A port of identicon library written in Java.

Good luck!

OTHER TIPS

One way to approach this is similar to a random sentence generator: Rather than a random sequence of letters or words, you can use simple grammar templates like "The (adjective) (noun) (transitive verbed) a (adjective) (noun)." Then pick random nouns etc. to fill it in.

So here, you could compose an icon by randomly selecting some small image pieces like a document icon, a person icon, a right arrow, a question mark, etc. Randomly colorize the pieces, using a randomly chosen color scheme. Randomly arrange the pieces together. Add a shadow. Stuff like that.

For avatars, this could work similar to Mr. Potato Head.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top