-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 –
它有什麼問題? –