exam

by Zhaoliang

HTML

<div id="drawing">

</div>

JavaScript

var draw = SVG('drawing').size(600,600); 
var border = draw.rect(600,600).fill('white').stroke('black');
var timer = setInterval(moveBall, 1);

var xvel = 1;
var yvel = 3;

// Set up the ball
var theball = draw.circle(60,60).move(draw.width()/2, draw.height()/2).fill('red').stroke('black');

// Set up the movement for ball
function moveBall() {
  if(theball.x() > draw.width()-theball.width()){
	 theball.x(draw.width()- theball.width());
	 xvel = -2;
  }
	else if (theball.x() < 0){
		theball.x(0);
		xvel = 1;
  }
	else if (theball.y() > draw.height()-theball.height()){
	 theball.y(draw.height()- theball.height());
	 yvel = -2;
		
  }
	else if (theball.y() < 0){
		theball.y(0);
		yvel = 3;
	
  } 
	else {
		theball.dx(xvel);
		theball.dy(yvel);
	}
}