-3
/* Constants */
var START_RADIUS = 1;
var INCREMENT = 1;
var CHANGE_COLORS_AT = 10;
var circle;
function start(){
//Circle is being added once in the start function.
circle = new Circle(START_RADIUS);
circle.setPosition(getWidth()/2, getHeight()/2);
add(circle);
//This is the command that will execute every 50 miliseconds.
setTimer(grow, 50);
}
function grow(){
//This will keep the circle from continually growing past the height of the (premade) canvas.
while(circle.getRadius()*2 != getHeight()){
START_RADIUS = START_RADIUS + INCREMENT;
circle.setRadius(START_RADIUS);
//Changes the color every +10 the radius grows.
if(circle.getRadius() % CHANGE_COLORS_AT == 0){
circle.setColor(Randomizer.nextColor());
}
}
}
这段代码是为了让一个不断增长的圆圈(直到直径达到画布的顶部)。这是针对学校的,并且正在使用来自网站'codehs.com'的javascript的非常简化的版本。我一直在研究这段代码,并希望得到一些关于如何解决它的见解。我想帮助我修复我的代码
getHeight'和其他getter如何定义? – Teemu
JavaScript!= Java –
它有什么问题? –