Animal Description Generator
in
Share your Work
•
2 years ago
Hi there!
Adjectives (300 words)
Long list of animals (441 words)
Colours (758 words)
All lists where obtained trough the Internet.
I made this sketch and I simply wanted to share. The code is not very clean, as it was written rather quickly.
The sketch chooses from a list of preexisting animals, and assigns an adjective, color and gives it a random name.
At last it collects data from Wikipedia and makes a description. It prints all the information to the console.
With the current settings, this sketch can produce 612081298828125000 unique animals (I think!).
The sketch consist of three sketches.
The main sketch:
- String[] adj=loadStrings("http://dl.dropbox.com/u/2621700/generator/adjectives.txt");
- String[] ani=loadStrings("http://dl.dropbox.com/u/2621700/generator/animalsExtended.txt");//remove 'Extended' for a shorter list, but with descriprions
- String[] col=loadStrings("http://dl.dropbox.com/u/2621700/generator/colours.txt");
- String animalDes,animal,adjective;
- void setup() {
- size(100,100,P2D);
- if (adj!=null) println("Loaded Adjectives!");
- if (ani!=null) println("Loaded Animals!");
- if (col!=null) println("Loaded Colours!");
- if (adj!=null&&ani!=null&&col!=null) println("Loading Succsfull! \n");
- fill(0,5);
- stroke(255);
- }
- void draw() {
- rect(-1,-1,width-1,height-1);
- point(width/2+25*cos(radians(millis()/10)),width/2+25*sin(radians(millis()/10)));
- if (mousePressed) {
- adjective=randomAdj();
- animal=randomAni();
- if(animal.indexOf('A')!=-1) {
- animalDes=animal.substring(animal.indexOf('A'))+'.';
- animal=animal.substring(0,animal.indexOf('A'));
- } else {
- animalDes=loadWikipedia(animal);
- }
- animalDes=mergeAdjective(animalDes,animal,adjective);
- println("\n"+ana(adjective)+' '+adjective+", "+randomCol()+" coloured "+animal+" named "+generateName(.38,round(random(3,11))));
- if(animalDes!=null) {println(animalDes);}
- //println();
- }
- }
- String randomAdj() {return adj[floor(random(adj.length))];}
- String randomAni() {return ani[floor(random(ani.length))];}
- String randomCol() {return col[floor(random(col.length))].trim();}
- String ana(String inString) {// puts 'A' or 'An' infront of the input string
- inString.trim();
- char t = inString.charAt(0);
- if (t=='a'||t=='e'||t=='i'||t=='o'||t=='u'||t=='y'||t=='A'||t=='E'||t=='I'|t=='O'|t=='U'|t=='Y') {
- return "An";
- } else {
- return "A";
- }
- }
- String mergeAdjective(String stringIn,String aniName,String adjIn) {//merges the desrciption text with the adjective
- aniName=aniName.toLowerCase();
- stringIn=stringIn.replaceAll(aniName,adjIn+" "+aniName);
- stringIn=stringIn.replaceAll(aniName+"s",adjIn+" "+aniName+"s");
- stringIn=stringIn.replaceAll(adjIn+' '+adjIn,adjIn);
- return stringIn;
- }
Note on the animal list: The animals can have descriptions embedded within the list. The description just have to start with an 'A'.
And here is the name generator part:
- char reW() {
- char out = ' ';
- switch(floor(random(6))) {
- case 0: out = 'a';break;
- case 1:out = 'e';break;
- case 2:out = 'i';break;
- case 3:out = 'o';break;
- case 4:out = 'u';break;
- case 5:out = 'y';break;
- }
- return out;
- }
- char reC() {
- char out = ' ';
- switch(floor(random(20))) {
- case 0:out = 'q';break;
- case 1:out = 'w';break;
- case 2:out = 'r';break;
- case 3:out = 't';break;
- case 4:out = 'p';break;
- case 5:out = 's';break;
- case 6:out = 'd';break;
- case 7:out = 'f';break;
- case 8:out = 'g';break;
- case 9:out = 'h';break;
- case 10:out = 'j';break;
- case 11:out = 'k';break;
- case 12:out = 'l';break;
- case 13:out = 'z';break;
- case 14:out = 'x';break;
- case 15:out = 'c';break;
- case 16:out = 'v';break;
- case 17:out = 'b';break;
- case 18:out = 'n';break;
- case 19:out = 'm';break;
- }
- return out;
- }
- String generateName(float t,int l) {//t determines what percentage of consonants
- String name = "";
- for(int i=0;i<=l;i++) {
- if(random(1)>t) {
- name=name+reW();
- } else {
- name=name+reC();
- }
- }
- return name;
- }
- String cleanTag(String stringIn,char stC,char enC) {//clear text between two 'tags'
- int sta=0;
- int end=0;
- String subString="";
- while(sta!=-1&&end!=-1) {
- sta=stringIn.indexOf(stC);
- end=stringIn.indexOf(enC);
- if(sta!=-1&&end!=-1) {
- for(int i=sta;i<=end;i++) {
- subString=subString+stringIn.charAt(i);
- }
- stringIn=stringIn.replace(subString,"");
- subString="";
- }
- else {
- }
- }
- return stringIn.trim();
- }
- String loadWikipedia(String siteName) {//loads a wikipedia article and removes the html and reference tags
- int sta =-1;
- int end =-1;
- int found=2;
- boolean f=false;
- //load
- siteName=siteName.trim();
- if(siteName.indexOf(" ")!=-1) siteName=siteName.replaceAll(" ","_");
- String[] site=loadStrings("http://en.wikipedia.org/wiki/"+siteName);
- String info="";
- //find intro
- if(site[1]!=null) {
- for(int i=0;i<site.length;i++) {
- if(site[i].indexOf("<tr>")>=0) {
- f=true;
- }
- if(site[i].indexOf("</tr>")>=0) {
- f=false;
- }
- if(site[i].indexOf("<p>")!=-1&&f==false) {
- info=site[i];
- break;
- }
- }
- //clean text noise
- info=cleanTag(info,'<','>');
- info=cleanTag(info,'[',']');
- info=cleanTag(info,'/','/');
- info=info.replaceAll(" "," ");
- }
- return info.trim();
- }
And here is a download link:
Download
Example Animals:
An icy, lincoln green coloured boston terrier named yaylhouiThe Boston Terrier is a breed of dog originating in the United States of America. This "American Gentleman" was accepted in 1893 by the American Kennel Club as a non-sporting breed. Color and markings are important when distinguishing this breed to the AKC standard. They should be either black, brindle or seal with white markings. Bostons are small and compact with a short tail and erect ears. They are intelligent and friendly and can be stubborn at times. The average life span of a Boston is 15+ years.
An annoyed, vermilion coloured squirrel named aapsuuSquirrels belong to a large family of small or medium-sized rodents called the Sciuridae. The family includes tree annoyed squirrels, ground annoyed squirrels, chipmunks, marmots (including woodchucks), flying annoyed squirrels, and prairie dogs. Squirrels are indigenous to the Americas, Eurasia, and Africa and have been introduced to Australia. Squirrels are first attested in the Eocene, about forty million years ago, and are most closely related to the mountain beaver and to dormice among living species.
Download links to the lists:A cruel, timberwolf coloured stork named iuicuoiyztStorks are large, long-legged, long-necked wading birds with long stout bills, belonging to the family Ciconiidae. They are the only family in the biological order Ciconiiformes, which was once much larger and held a number of families.
Adjectives (300 words)
Long list of animals (441 words)
Colours (758 words)
All lists where obtained trough the Internet.
Problems with this sketch:
The sketch doesn't know if the Wikipedia page is a "[animal name] may also refer to:" page.
Try it out and leave some feedback :)