HTML and CSS Reference
In-Depth Information
ball . y += ball . velocityy ;
ball . x += ball . velocityx ;
In Figure 5-20 , you can see what this application looks like when executed in a web browser.
Figure 5-20. Ball bouncing with elasticity and gravity applied
With gravity applied,thebounceisnotexactlyasyoumightexpect.Gravityisalwayspullingdown
on our object, so the effect of a loss of y velocity due to an elastic bounce is pronounced.
The full code is shown in Example 5-16 .
Example 5-16. Simple gravity with bounce and elasticity
<!doctype html>
<html lang= "en" >
<meta charset= "UTF-8" >
<title> CH5EX16: Gravity With A Vector With Bounce And Elasticity </title>
< script src = "modernizr.js" >< /script>
< script type = "text/javascript" >
Search WWH ::

Custom Search