HTML and CSS Reference
In-Depth Information
var
var tempBall ;
var
var tempX ;
var
var tempY ;
var
var tempSpeed ;
var
var tempAngle ;
var
var tempRadius ;
var
var tempRadians ;
var
var tempvelocityx ;
var
var tempvelocityy ;
theCanvas = document . getElementById ( "canvasOne" );
context = theCanvas . getContext ( "2d" );
for
for ( var
var i = 0 ; i < numBalls ; i ++ ) {
tempRadius = 5 ;
var
var placeOK = false
false ;
while
while ( ! placeOK ) {
tempX = tempRadius * 3 + ( Math . floor ( Math . random () * theCanvas . width )
- tempRadius * 3 );
tempY = tempRadius * 3 + ( Math . floor ( Math . random () * theCanvas . height )
- tempRadius * 3 );
tempSpeed = 4 ;
tempAngle = Math . floor ( Math . random () * 360 );
tempRadians = tempAngle * Math . PI / 180 ;
tempvelocityx = Math . cos ( tempRadians ) * tempSpeed ;
tempvelocityy = Math . sin ( tempRadians ) * tempSpeed ;
tempBall = { x : tempX , y : tempY , nextX : tempX , nextY : tempY , radius : tempRadius ,
speed : tempSpeed , angle : tempAngle , velocityx : tempvelocityx ,
velocityy : tempvelocityy , mass : tempRadius };
placeOK = canStartHere ( tempBall );
}
balls . push ( tempBall );
}
function
function canStartHere ( ball ) {
var
var retval = true
true ;
for
for ( var
var i = 0 ; i < balls . length ; i ++ ) {
iif ( hitTestCircle ( ball , balls [ i ])) {
retval = false
false ;
}
}
return
return retval ;
}
function
function gameLoop () {
window . setTimeout ( gameLoop , 20 );
Search WWH ::




Custom Search