【发布时间】:2015-08-24 19:21:46
【问题描述】:
我创建了 3 个函数,在画布上绘制了一个圆圈。现在我希望 3 个函数之一在 draw() 函数中随机执行。我怎么能意识到这一点?
function drawcircle1()
{
var radius = x * 5;
ctx.beginPath();
ctx.arc(ballx * 100, canvasHeight / 2, radius, 0, 2 * Math.PI, false);
ctx.fillStyle = 'yellow';
ctx.fill();
}
function drawcircle2()
{
var radius = x * 5;
ctx.beginPath();
ctx.arc(ballx * 100, canvasHeight / 2, radius, 0, 2 * Math.PI, false);
ctx.fillStyle = 'blue';
ctx.fill();
}
function drawcircle3()
{
var radius = x * 5;
ctx.beginPath();
ctx.arc(ballx * 100, canvasHeight / 2, radius, 0, 2 * Math.PI, false);
ctx.fillStyle = 'orange';
ctx.fill();
}
function draw() {
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
// here should the draw function pic random one of the 3 drawcircle functions
}
【问题讨论】:
标签: javascript html canvas draw