Created
November 15, 2011 00:39
-
-
Save gentimouton/1365715 to your computer and use it in GitHub Desktop.
Crappy Noun generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<script type="text/javascript"> | |
var consonants = ['b','c','d','f']; | |
var vowels = ['a','e','i','o','u','y']; | |
var consBeg = ['b','c','f','g','k','p','q']; | |
var consEnd = ['j','l','r','s','z']; | |
var consAloneNoH = ['d','m','n','t','v','w','x']; | |
var consAlone = ['chr','shr','str','sr', 'sl', 'sj', 'sm', 'sn', 'dr','dj']; | |
// called by body.onLoad and the 'reload' button | |
function newWord() { | |
var wd = buildWord(2+myRand(2)); | |
document.getElementById("textField").value = capitaliseFirstLetter(wd); | |
} | |
// recursively build a word with a certain number of syllables | |
function buildWord(numSyllables) { | |
if(numSyllables <= 0) { | |
return ''; | |
} | |
else { | |
//var syllable = consonants[myRand(consonants.length)] + vowels[myRand(vowels.length)]; | |
var syllable = getCons() + getDiphtong(); | |
return syllable + buildWord(numSyllables-1); | |
} | |
} | |
// build a group of consonants | |
function getCons() { | |
var consB = consBeg[myRand(consBeg.length)]; | |
var consE = consEnd[myRand(consEnd.length)]; | |
var consA = getConsAlone(); | |
var r = Math.floor(Math.random()*10); | |
switch(r) { | |
case 0: case 1: return consB; | |
case 2: case 3: return consE; | |
case 4: return consB+consE; | |
case 5: case 6: case 7: case 8: case 9: return consA; | |
} | |
} | |
// build a consonant group | |
function getConsAlone() { | |
var r = Math.floor(Math.random()*12); | |
switch(r) { | |
case 0: return 'h'; | |
case 1: case 2: case 3: case 4: case 5: return consAloneNoH[myRand(consAloneNoH.length)]; | |
case 6: return consAloneNoH[myRand(consAloneNoH.length)]+'h'; | |
default: return consAlone[myRand(consAlone.length)]; | |
} | |
} | |
// build a diphtong | |
function getDiphtong() { | |
var r = Math.floor(Math.random()*4); | |
switch(r) { | |
case 0: case 1: case 2: return vowels[myRand(vowels.length)]; | |
case 3: return vowels[myRand(vowels.length)]+'n'; | |
} | |
} | |
// return a random integer between 0 and maxValue | |
function myRand(maxValue) { | |
return(Math.floor(Math.random() * maxValue)); | |
} | |
// captialize the first letter | |
function capitaliseFirstLetter(string) { | |
return string.charAt(0).toUpperCase() + string.slice(1); | |
} | |
</script> | |
</head> | |
<body onload="newWord()"> | |
<input type="text" id="textField" style="width:300px"></input> | |
<button id="launcher" onclick="newWord()">Reload</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment