Questions & Answers
In the following code:
var ball;
function start(){
ball = new Circle(20);
add(ball);
setTimer(draw, 20);
}
function draw(){
ball.move(2, 2);
}
When will the function draw be called? ✔️Correct Ans-Every 20 milliseconds
Which statement will call a function animate every 50 milliseconds? ✔️Correct Ans-
setTimer(animate, 50);
9.1.5 Crazy Ball ✔️Correct Ans-var RADIUS = 100;
var circle;
function start(){
circle = new Circle(RADIUS);
circle.setPosition(getWidth()/2, getHeight()/2);
,add(circle);
setTimer(crazyBall, 100);
}
function crazyBall(){
var x = Randomizer.nextInt(RADIUS, getWidth()-RADIUS);
var y = Randomizer.nextInt(RADIUS, getHeight()- RADIUS);
circle.setPosition(x,y);
circle.setColor(Randomizer.nextColor());
}
What does this program do?
function drawCircle(x, y, radius, color){
var circle = new Circle(radius);
circle.setPosition(x, y);
circle.setColor(color);
add(circle);
}
function start(){
setTimer(draw, 50);
}
function draw(){
var color = Randomizer.nextColor();
var centerX = getWidth()/2;
,var centerY = getHeight()/2;
var radius = 100;
drawCircle(centerX, centerY, radius, color);
} ✔️Correct Ans-Draws several randomly colored circles at the center of the canvas by drawing 1
every 50 milliseconds.
Which statement would stop the timer in the following program?
function drawCircle(x, y, radius, color){
var circle = new Circle(radius);
circle.setPosition(x, y);
circle.setColor(color);
add(circle);
}
function start(){
setTimer(draw, 50);
}
function draw(){
var color = Randomizer.nextColor();
var centerX = getWidth()/2;
var centerY = getHeight()/2;
var radius = 100;
drawCircle(centerX, centerY, radius, color);
} ✔️Correct Ans-stopTimer(draw);
, 9.2.5: Growing Circle ✔️Correct Ans-var START_RADIUS = 1;
var INCREMENT = 1;
var CHANGE_COLORS_AT = 10;
var circle;
var MAX_RADIUS = 240;
var counter = 0;
function start(){
circle = new Circle(START_RADIUS);
circle.setPosition(getWidth()/2, getHeight()/2);
add(circle);
setTimer(draw, 50);
}
function draw(){
START_RADIUS = START_RADIUS + INCREMENT;
circle.setRadius(START_RADIUS);
counter++;
if(START_RADIUS % 10 == 0){
circle.setColor(Randomizer.nextColor());
}
if(counter == MAX_RADIUS){
stopTimer(draw);