1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| var canvasCommand = (function () { var canvas = document.getElementById('canvas') var ctx = canvas.getContext('2d') var Action = { fillstyle: function (c) { ctx.fillstyle = c }, fillRect: function (x, y, width, height) { ctx.fillRect(x, y, width, height) }, strokestyle: function (c) { ctx.strokestyle = c }, strokeRect: function (x, y, width, height) { ctx.strokeRect(x, y, width, height) }, fillText: function (text, x, y) { ctx.fillText(text, x, y) }, beginPath: function () { ctx.beginPath() }, moveTo: function (x, y) { ctx.moveTo(x, y) }, lineTo: function (x, y) { ctx.lineTo(x, y) }, arc: function (x, y, r, begin, end, dir) { ctx.arc(x, y, r, begin, end, dir) }, fill: function () { ctx.fill() ctx.stroke() }, stroke: function () {}, } return { excute: function (msg) { if (!msg) { return } if (msg.length) { for (var i = 0, len = msg.length; i < len; i++) { arguments.callee(msg[i]) } } else { msg.param = Object.prototype.toString.call(msg.param) === '[object Array]' ? msg.param : [msg.param] Action[msg.command].apply(Action, msg.param) } }, } })()
|