マクロ
選択文字列を渦巻状に整形する。 2ちゃんねるの書き込みより。 悪用厳禁。
選択文字列を渦巻状に整形する。 2ちゃんねるの書き込みより。 悪用厳禁。
function Spiral(dr, reverseY) { this.dr = dr; this.reverseY = reverseY; } Spiral.prototype.setAngle = function(angle) {this.angle = angle} Spiral.prototype.r = function(angle) {return this.dr * angle / (2 * Math.PI);} Spiral.prototype.x = function(angle) { return this.r(angle) * Math.cos(angle); } Spiral.prototype.y = function(angle) { var reg = this.reverseY ? -1 : 1; return this.r(angle) * Math.sin(angle) * reg; } Spiral.prototype.angleAtLength = function(l) { return Math.sqrt(4 * Math.PI * l / this.dr); } //冒頭の例はdr=3, pitch=2, reverse=true, ratio=1.5 var dr = 3; //1周あたりの半径の変化量 var pitch = 2; //文字同士の間隔 var reverseY = true; //Y軸方向を反転するか否か var ratio = 1.5; //横/縦の比率(1より大きいと横長) var sp = new Spiral(dr, reverseY); document.selection.SelectLine(); document.selection.Text = getSpiralString(document.selection.Text, sp, pitch, ratio); function getSpiralString(str, spiral, pitch, ratio) { str = str.replace(/\r|\n/g, ""); var lineCount = Math.floor(spiral.r(spiral.angleAtLength(str.length * pitch)) * 2) + 2; var lineLength = Math.floor(lineCount * ratio); var centerX = Math.floor(lineLength / 2); var centerY = Math.floor(lineCount / 2);
var lines = new Array(lineCount); for(var i = 0; i < lineCount; i++) { lines[i] = ""; for(var j = 0; j < lineLength; j++) {lines[i] += " " ;} } var adjuster = 1; //0から始めるとちょっと汚いので、調整用に。 for(var i = 0; i < str.length; i++) { var angle = spiral.angleAtLength(i * pitch + adjuster); var x = Math.round(spiral.x(angle) * ratio) + centerX; var y = Math.round(spiral.y(angle)) + centerY; lines[y] = lines[y].substring(0, x - 1) + str.charAt(i) + lines[y].substring(x); } var ret = "" for(var i = 0; i < lineCount; i++) { ret += lines[i] + "\n"; } ret = ret.replace(/^( +\n)*/, ""); ret = ret.replace(/\n( +\n)*$/, ""); return ret + "\n"; }