Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 158 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

I am looking for code to automatically generate lots of colorful unicorns. I would also like to randomly generate clouds and rainbows in the image. How does one go about automatically generating meaningful images?

share|improve this question

migrated from Mar 31 '10 at 23:09

This question came from our site for professional and enthusiast programmers.

How meaningful are images of unicorns and rainbows? – cdjaco Mar 31 '10 at 22:49
I am pretty sure that's a library. Doubt they wrote it themselves – Pyrolistical Mar 31 '10 at 22:50
Would you like to repeat last years cornification? – 0xA3 Mar 31 '10 at 22:51
In python, it's easy. import unicorns – Jeff B Mar 31 '10 at 22:52
well this was better than last year. and I couldn't find such a library. maybe they did write it themselves – Pyrolistical Mar 31 '10 at 22:53
What language do you use? – user142723 Mar 31 '10 at 23:00
See here:… – Jon Seigel Mar 31 '10 at 23:00
I love how thins get migrated to meta just to be closed as a duplicate. – Earlz Mar 31 '10 at 23:10
There must be a jquery plugin for that too – Damien Pirsy Feb 10 '12 at 21:08

10 Answers 10

up vote 13 down vote accepted

In python:

from libutils import unicorns

share|improve this answer

There you go: I just published the code. This is

import hashlib
from avatar import create_avatar

hash = hashlib.md5("").hexdigest()

# Creates a BMP file of 256x256 pixels (see docstring of create_avatar)
f = open("unicorn.bmp", "wb")
f.write(create_avatar(128, int(hash, 16)))
share|improve this answer

This code in JavaScript will do:


You can use it e.g. within the href of a hyperlink or add it to the onclick handler of an image in any website and you will get the most colorful unicorns and rainbows.

Or simply copy and paste it to the address bar of your browser and press return ;-)

share|improve this answer

Well you want to start with some line only unicorns that are encoded in a "color by number" manner, so that places that should have like colors, such as hoves, can be easily identified. For each number randomly assign a color, you could add extra rules to ensure the color is a pretty color, such as pastels. I would store the shapes of the unicorns as vector graphics. That way you can randomly move, rotate, and size the unicorns. The clouds would also be pre-designed and stored as vector graphics. Be sure the Z order of the clouds places them behind the unicorns, or randomly assign the z order to give the effect that the unicorns are flying through the clouds.

Yes, I know unicorns don't fly normally, but they are magical after all, right?

share|improve this answer

If you want to do it programatically:

Clouds can be created using some fractal algorithm. Rainbows can be created using a simple color-spectrum rendering algorithm.

Unicorns don't exist until .NET5

share|improve this answer

Of course there is a Linq function for that:

var unicorns =  from a in animals
                from r in rainbows
                from c in clouds
                where a.Species == Species.Unicorn
                select new Avatar(a, r, c).Randomize();
share|improve this answer

Here's the code I used, 100 at a time:


import md5

print "<html><body>"

for num in range(100):
    email = "something+bgpxi" + str(num) + ""
    print "<p>" + email + "<p>"
    print '<p><img src="' + + '?s=128"></p>'
    print '<p><img src="' + + '"></p>'

print "</html></body>"

"something" is your gmail account (or other email that lets you add a bit after +). "bgpxi" is just some random junk to thwart the obvious privacy issue with gravatar, that if someone can guess your email address, they can confirm that guess by matching the MD5 sum. A dictionary attack, in essence.

That's because I was picking a better icon for SO, though: otherwise any old string with a varying part will do.

Come to think of it, it's just for a day and SO doesn't actually use your email address for anything unless you tell it to, so for my purposes anything it will accept as an email address would do.

share|improve this answer


Write a small program to parse user names off and then further parse the url to their icons.

Problem is this might not work after tomorrow. I am still working on that problem.

share|improve this answer

Add a 400 unicorns to the page (sorry, I have almost no js skills)

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .