ローマ数字に変換?5進数?
return num.toString (5).split ('').reverce (). map (xxx,['I','V','X','L','M','C']).reverse ().join ('');
しようとも、失敗する。
なんだか、このコードは納得していない。
明日も早いのに、こうしてる場合じゃないだろ>俺
この間の司会もカミまくり!はずかしい。
かぼちゃも食べたし、足がつらないことを祈ろう。zzz
var toRoman = (function () { var unit = [ [], ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'], ['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'], ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM'], ['', 'M', 'MM', 'MMM' ] ]; var toQuinary = (function (unit) { return function (r, c, i, a) { return unit[a.length - i][c] + r; }; })(unit); return function (num, i) { if (isNaN (num + '')) throw new Error ('Not number'); if (num < 1 || 3999 < num) throw new Error ('Number is outside the scope.'); return num.toString ().split ('').reduceRight (toQuinary, ''); }; })(); alert ([11,12,14,18,24,43,99,495,1888,3999].map (toRoman).join("\n")); <
html5で複雑な円グラフを描画
http://oshiete.goo.ne.jp/qa/7134565.html
どこが複雑なのかよくわからないが、書いてみたら Fujillin さんとかぶった。
添え字とか、角度の計算を自動にしただけ++。
<!DOCTYPE html> <html lang="ja"> <title>Test</title> <meta charset="utf-8"> <body> <canvas id="HOGE" width="800" height="400"> canvas による描画 </canvas> <script> var dt = [ { value: 512, radius: 90, color: '#080', caption: 'A' }, { value: 6534, radius: 30, color: '#f00', caption: 'B' }, { value: 3056, radius: 20, color: '#008', caption: 'C' } ]; var canvas = document.getElementById ('HOGE'); var op = { ctrx: canvas.getContext ('2d'), x: canvas.offsetWidth / 2 |0, y: canvas.offsetHeight / 2 |0, r: 180 }; var total = dt.reduce (function (rst, obj) { return rst + obj.value; }, 0); var drawArc = function () { var square = -90; var sin = Math.sin; var cos = Math.cos; var deg = Math.PI / 180; return function (obj) { var ctrx = this.ctrx; var square2 = square + (360 / 100) * obj.rate * 100; ctrx.fillStyle = obj.color; ctrx.strokeStyle = 'black'; ctrx.beginPath (); ctrx.moveTo (this.x, this.y); ctrx.arc (this.x, this.y, obj.radius * this.r / 100 |0, square * deg, square2 * deg, false); ctrx.lineTo (this.x, this.y); ctrx.closePath (); ctrx.fill (); ctrx.stroke (); square = square2; }; } (); var drawCaption = function () { var offsetX = 10; var offsetY = 8; var color = 'white'; var font = "18px 'MS Pゴシック'"; return function (obj) { var y = this.y - this.r * obj.radius / 100; this.ctrx.fillStyle = color; this.ctrx.font = font; this.ctrx.fillText (obj.caption, this.x + offsetX, y + offsetY); }; } (); op.ctrx.arc (op.x, op.y, op.r, 0, 360, false); op.ctrx.fillStyle = 'silver'; op.ctrx.fill (); dt.forEach (function (obj) { obj.rate = obj.value / this; }, total); dt.forEach (drawArc, op); dt.forEach (drawCaption, op); </script>