HTML and CSS Reference
In-Depth Information
}
var
var numBalls = 100 ;
var
var maxSize = 8 ;
var
var minSize = 5 ;
var
var maxSpeed = maxSize + 5 ;
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 tempXunits ;
var
var tempYunits ;
theCanvas = document . getElementById ( "canvasOne" );
context = theCanvas . getContext ( "2d" );
for
for ( var
var i = 0 ; i < numBalls ; i ++ ) {
tempRadius = Math . floor ( Math . random () * maxSize ) + minSize ;
tempX = tempRadius * 2 + ( Math . floor ( Math . random () * theCanvas . width ) - tempRadius * 2 );
tempY = tempRadius * 2 + ( Math . floor ( Math . random () * theCanvas . height ) - tempRadius * 2 );
tempSpeed = maxSpeed - tempRadius ;
tempAngle = Math . floor ( Math . random () * 360 );
tempRadians = tempAngle * Math . PI / 180 ;
tempXunits = Math . cos ( tempRadians ) * tempSpeed ;
tempYunits = Math . sin ( tempRadians ) * tempSpeed ;
tempBall = { x : tempX , y : tempY , radius : tempRadius , speed : tempSpeed , angle : tempAngle ,
xunits : tempXunits , yunits : tempYunits }
balls . push ( tempBall );
}
function
function gameLoop () {
window . setTimeout ( gameLoop , 20 );
drawScreen ()
}
gameLoop ();
}
< /script>
Search WWH ::




Custom Search