代码拉取完成,页面将自动刷新
function Canvas() {
this.canvas = document.getElementById('canvas');
this.context = this.canvas.getContext('2d');
this.colors = ['#C03', 'DarkKhaki', 'yellow', 'grey', 'pink',
'green', 'orange', 'brown', 'Magenta', 'DeepSkyBlue'];
}
Canvas.prototype.drawGrid = function(color, stepx, stepy) {
var ctx = this.context;
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
ctx.save();
ctx.strokeStyle = color;
ctx.lineWidth = 0.5;
for (var i = stepx + 0.5; i < ctx.canvas.width; i += stepx) {
ctx.beginPath();
ctx.moveTo(i, 0);
ctx.lineTo(i, ctx.canvas.height);
ctx.stroke();
ctx.closePath();
}
for (var i = stepy + 0.5; i < ctx.canvas.height; i += stepy) {
ctx.beginPath();
ctx.moveTo(0, i);
ctx.lineTo(ctx.canvas.width, i);
ctx.stroke();
ctx.closePath();
}
ctx.restore();
};
Canvas.prototype.drawBall = function(ball) {
var ctx = this.context;
var m = 50 * ball.x + 25,
n = 50 * ball.y + 25;
ctx.save();
ctx.fillStyle = '#C03';
ctx.fillStyle = this.colors[ball.color];
ctx.shadowColor = 'black';
ctx.shadowOffsetX = 4;
ctx.shadowOffsetY = 4;
ctx.shadowBlur = 12;
ctx.beginPath();
ctx.arc(m, n, 23, 0, Math.PI * 2, false);
ctx.closePath();
ctx.fill();
ctx.restore();
};
Canvas.prototype.drawCheckBox = function(m, n) {
var ctx = this.context;
ctx.save();
ctx.strokeStyle = 'rgba(0, 0, 0, 0.4)';
ctx.strokeRect(m-25, n-25, 50, 50);
ctx.restore();
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。