Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
通常のテキストから縦書き短冊風テキストを生成するスクリプト
/*
* tanzaku.js
*
* Created by FUKUBAYASHI Yuichiro on 2012/07/06
* Copyright (c) 2012, FUKUBAYASHI Yuichiro
*
* last update: <2012/07/07 02:08:54>
*/
TANZAKU = {
N_PER_LINE:26,
N_LINE:2,
hankaku:new Array("ガ","ギ","グ","ゲ","ゴ","ザ","ジ","ズ","ゼ","ゾ","ダ","ヂ",
"ヅ","デ","ド","バ","ビ","ブ","ベ","ボ","パ","ピ","プ","ペ","ポ","","",
"","","","","","","","","","","","","","","","","","",
"","","","","","ソ","","","","","","","","","","","","",
"","","","","","","","","","","","","","","","","",""),
zenkaku:new Array("","","","","","","","","","","","",
"","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","",
"","","","","","","","",""),
hankaku2: new Array("1","2","3","4","5","6","7","8","9","0",
"`","~","!","@","#","$","%","^","&","*",
"(",")","-","_","=","+","[","{","}","]",
"|",";",":",",","<",".",">","/","?"
),
zenkaku2: new Array("","","","","","","","","","",
"","","","","","","","","","",
"","","","_","","","","","","",
"","","","","","","","",""
),
getTanzaku : function(org_txt){
var onegai = org_txt;
onegai = onegai.replace(/[A-Za-z]/g, function(s) {
return String.fromCharCode(s.charCodeAt(0) + 65248);
});
while(onegai.match(/[ヲ-ン1234567890\~!@#\$%\^&\*()\-_=+\[\]{}|;:,<.>/?]/)){
for(var i=0;i<TANZAKU.hankaku.length;i++){
onegai = onegai.replace(TANZAKU.hankaku[i],TANZAKU.zenkaku[i]);
}
for(var i=0;i<TANZAKU.hankaku2.length;i++){
onegai = onegai.replace(TANZAKU.hankaku2[i],TANZAKU.zenkaku2[i]);
}
}
onegai = onegai.replace(/[ー−―‐〜〜〜]/g, "");
onegai = onegai.replace(/ /g, " ");
onegai = onegai.replace(/[{([「]/g,"");
onegai = onegai.replace(/[})]」]/g,"");
var lines = onegai.split(/\n/);
var n_per_line = 0;
for(var i=0;i<lines.length;i++){
if(lines[i].length>n_per_line){
n_per_line = lines[i].length;
}
}
var tanzaku = "";
var half_n_lines=Math.floor((lines.length-1)/2);
for(var i=0; i<half_n_lines; i++){
tanzaku += "";
}
tanzaku += "";
for(var i=0; i<lines.length-1-half_n_lines;i++){
tanzaku += "";
}
tanzaku += "\n";
for(var i=0;i<n_per_line;i++){
tanzaku+="";
for(var j=lines.length-1;j>=0;j--){
tanzaku += (lines[j][i] === undefined ? " " : lines[j][i]);
}
tanzaku+="\n";
}
tanzaku += "╰̚";
for(var i=0;i<lines.length;i++){
tanzaku += "";
}
tanzaku += "┛⁾⁾";
return tanzaku;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment