Created
February 29, 2016 17:48
-
-
Save alexvandesande/a0b2a36c20678c268091 to your computer and use it in GitHub Desktop.
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
var base10 = $('input[id="base10"]').numeric({ negative: false }); | |
function syllable(n){ | |
consonants = 'bcdfghjklmnprstvwz'; // consonants except hard to speak ones | |
vowels = 'aeiou'; // vowels | |
all = consonants + vowels; // all | |
text = ''; | |
syllableStr = ""; | |
if (n<90) { | |
// If less than 18*5 then return Consoant + Vowel | |
syllableStr = consonants[Math.floor(n/5)%18] + vowels[n%5]; | |
} else if (n<=180) { | |
// Less than 18*5*2 then return Vowel + Consoant | |
m = n - 90; | |
syllableStr = vowels[Math.floor(m/18)%5] + consonants[m%18] ; | |
} else if (n <= 630 ) { | |
// Less than 5*18*5 then return Vowel + Consoant + Vowel | |
m = n - 180; | |
syllableStr = vowels[Math.floor(m/90)%5] + consonants[Math.floor(m/5)%18] + vowels[m%5] ; | |
} else { | |
// Less than 5*18*5 then return Consoant + Vowel + Consoant | |
m = n - 630; | |
syllableStr = consonants[Math.floor(m/90)%18] + vowels[Math.floor(m/18)%5] + consonants[m%18] ; | |
} | |
return syllableStr; | |
} | |
base10.change(function () { | |
var base10Num = $(this).val(); | |
var base2250Num = []; | |
var base2250Str = []; | |
//convert to base2250 | |
for (i=base10Num; i > 0; i = Math.floor(i/2250)){ | |
base2250Num.unshift( i % 2250 ); | |
//convert numbers to sillables | |
base2250Str.unshift(syllable(i % 2250)); | |
}; | |
//remove unecessary spaces | |
var outputWord = base2250Str[0]; | |
joinwords = false; | |
for (index = 1; index < base2250Str.length; ++index) { | |
thisSyl = base2250Str[index]; | |
lastSyl = base2250Str[index-1] | |
if (joinwords==true) { | |
joinwords = false; | |
} else if (lastSyl.length==thisSyl.length) { | |
joinwords = true; | |
} else if ( "aeiou".indexOf(lastSyl.slice(-1))==-1 && "aeiou".indexOf(thisSyl.slice(0,1))==-1 ) { | |
joinwords = true; | |
} else if ( "aeiou".indexOf(lastSyl.slice(-1))!=-1 && "aeiou".indexOf(thisSyl.slice(0,1))!=-1 ) { | |
joinwords = true; | |
} | |
separator = joinwords==true ? "":" "; | |
outputWord += separator + base2250Str[index]; | |
}; | |
$('input[id="base2250"]').val(outputWord); | |
$('input[id="base2250Num"]').val(base2250Num.join(" ")); | |
$('input[id="base16"]').val(parseInt(base10Num).toString(16)); | |
//parseInt(hexString, 16); | |
}); | |
$(document).ready(function() { | |
$("li:first-child").hide(); | |
$("#y").hide(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment