HTML and CSS Reference
In-Depth Information
var
var balls = new
new Array ();
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 ;
var
var friction = . 01 ;
theCanvas = document . getElementById ( "canvasOne" );
context = theCanvas . getContext ( "2d" );
for
for ( var
var i = 0 ; i < numBalls ; i ++ ) {
tempRadius = Math . floor ( Math . random () * maxSize ) + minSize ;
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 = maxSpeed - tempRadius ;
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 , radius : tempRadius , speed : tempSpeed ,
angle : tempAngle , velocityx : tempvelocityx , velocityy : tempvelocityy ,
mass : tempRadius * 8 , nextx : tempX , nexty : tempY };
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 ;
}
Search WWH ::




Custom Search