Last active
February 24, 2017 07:41
-
-
Save sftblw/fb27d3f8ef39acf3b3e02e426b068358 to your computer and use it in GitHub Desktop.
하우스: 비효율적으로 신음을 생성
This file contains hidden or 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
// https://twitter.com/5duckU3U/status/832268017186676737 | |
// @5duckU3U: 떡커,,, 이것만 기억하면 당신도 신음마스터! 》하우스《 입니다... | |
// ㅎ ㅏ ㅇ ㅜ ㅅ ㅡ를 조합하면 어떤 신음도 만들 수잇읍니다 | |
// 사용예시 》하우스! 하우..스...!(x) 하읏.. 으우... 읏...핫...!!(o) | |
// 처음엔 자, 모, 받침 배열로 구분해서 시작했으나 | |
// 웹상의 자료의 공식을 쓸 거면 완성형 문자를 쓰는 게 편하다는 걸 파악함. | |
var source_string = '하웃으'; | |
var zaum_idx_list = []; | |
var moeum_idx_list = []; | |
var batchim_idx_list = [0, 0]; | |
// 소스 문자열에서 자모받침 분리해서 그 인덱스를 배열에 쌓기 | |
// split('')까지 안 해도 되긴 하는데 쓰고보니 이렇게 나왔고 고치기 귀찮습니다 | |
// 제일 깔끔한 자료: https://regentag.github.io/rust/2015/04/26/hangul_jamo/ | |
source_string.split('').forEach( (letter) => { | |
// '가' 에서 시작하는 한글 완성형일거라고 가정합니다. | |
// 다른 구역에 있는 자모세트 이런 건 고려 안 하는 게 편할 것 같아서 그만... | |
var offset = letter.charCodeAt(0) - '가'.charCodeAt(0); | |
// 문서에 있던 공식대로 적당히 분리, 인덱스를 추출 | |
var zaum_idx = ((offset) / (21 * 28)) | 0; | |
var moeum_idx = (offset % (21 * 28) / 28) | 0; | |
var batchim_idx = offset % 28; | |
zaum_idx_list.push(zaum_idx); | |
moeum_idx_list.push(moeum_idx); | |
if (batchim_idx != 0) batchim_idx_list.push(batchim_idx); | |
}); | |
// 조합해서 하나의 단어를 만들어냅니다. | |
function makeLetter() { | |
var sel_zaum_idx = zaum_idx_list[Math.random()*zaum_idx_list.length | 0]; | |
var sel_moeum_idx = moeum_idx_list[Math.random() * moeum_idx_list.length | 0]; | |
var sel_batchim_idx = batchim_idx_list[Math.random() * batchim_idx_list.length | 0]; | |
// 역시 위의 공식대로. | |
var letter = String.fromCharCode('가'.charCodeAt(0) | |
+ ((sel_zaum_idx * 21) + sel_moeum_idx) * 28 + sel_batchim_idx); | |
return letter; | |
} | |
// 설명생략 | |
function makeWord() { | |
var word = ''; | |
for(var i = 0; i < Math.random() * 3 + 0; i++) { | |
word += makeLetter(zaum_idx_list, moeum_idx_list, batchim_idx_list); | |
} | |
for(var i = 0; i < Math.random() * 3 + 1; i++) { | |
word += '.'; | |
} | |
return word; | |
} | |
// 설명생략 | |
function makeSentence(count) { | |
var sentence = ''; | |
for(var i = 0; i < count; i++) { | |
sentence += makeWord(zaum_idx_list, moeum_idx_list, batchim_idx_list); | |
sentence += ' '; | |
} | |
return sentence; | |
} | |
console.log(makeSentence(20)); | |
// 추가로 참고한 자료 | |
// http://hanpsy.tistory.com/2 | |
// http://finsternis.tistory.com/380 | |
// 나중에 제대로 할 거면 유니코드 홈페이지에서 문서를 좀 찾아봐야할듯. | |
// 한글이 완성형만 있는 게 아니고 두 그룹이 더 있더라구요. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment