我创建了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
}