var NUM_CIRCLES = 15;
var MIN_RADIUS = 10;
var MAX_RADIUS = 40;
var DELAY = 500;
function start(){
drawCircles();
setTimer(update, DELAY);
}
function drawCircles(){
for(var i = 0; i < NUM_CIRCLES; i++){
circle = new Circle(Randomizer.nextInt(MIN_RADIUS, MAX_RADIUS));
var x = Randomizer.nextInt(MIN_RADIUS, getWidth() - MAX_RADIUS);
var y = Randomizer.nextInt(MIN_RADIUS, getHeight() - MAX_RADIUS);
circle.setPosition(x, y);
add(circle);
}
}
function update(){
var colors = Randomizer.nextColor();
circle.setColor(colors);
}
编写一个程序,在NUM_CIRCLES
到MIN_RADIUS
的不同大小的屏幕上创建MAX_RADIUS
个圈子列表。每DELAY
毫秒,获得一个随机颜色并将所有圆圈更改为此颜色。所有圆圈应始终具有相同的颜色。
答案 0 :(得分:0)
setTimer(update, DELAY);
这里当您调用更新功能时,您没有()更新后将其更改为:
setTimer(update(), DELAY);