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
8  
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
4  
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
1  
What language do you use? –  user142723 Mar 31 '10 at 23:00
4  
See here: meta.stackoverflow.com/questions/37328/… –  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
add comment

migrated from stackoverflow.com Mar 31 '10 at 23:09

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

10 Answers

up vote 13 down vote accepted

In python:

from libutils import unicorns

unicorns.generate()
share|improve this answer
add comment

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

import hashlib
from avatar import create_avatar

hash = hashlib.md5("your.email@address.here").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)))
f.close()
share|improve this answer
add comment

This code in JavaScript will do:

javascript:(function(){var%20d=document,j=d.getElementById('__cornify_nodes'),k=null;var%20files=['http://cornify.com/js/cornify.js','http://cornify.com/js/cornify_run.js'];if(j){cornify_add();}else{k=d.createElement('div');k.id='__cornify_nodes';d.getElementsByTagName('body')[0].appendChild(k);for(var%20l=0;l<files.length;l++){j=d.createElement('script');j.src=files[l];k.appendChild(j);}}})();

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
add comment

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
add comment

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
add comment

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
add comment

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

#!/usr/bin/python

import md5

print "<html><body>"

for num in range(100):
    email = "something+bgpxi" + str(num) + "@gmail.com"
    print "<p>" + email + "<p>"
    print '<p><img src="http://unicornify.appspot.com/avatar/' + md5.new(email).hexdigest() + '?s=128"></p>'
    print '<p><img src="http://unicornify.appspot.com/avatar/' + md5.new(email).hexdigest() + '"></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
add comment

Simple.

Write a small program to parse user names off stackoverflow.com 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 comment

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

 javascript:(function(){var%20d=document,k=null;k=d.createElement('div');k.id='__hh';d.getElementsByTagName('body')[0].appendChild(k);for(var%20l=0;l<400;l++){j=d.createElement('img');j.src='http://unicornify.appspot.com/avatar/6836267883ea7234253b2'+l+'f222dbbc?s=128&d=identicon&r=PG';k.appendChild(j);}})();
share|improve this answer
add comment

You must log in to answer this question.

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