HTML and CSS Reference
In-Depth Information
To move the circle up the screen, we would make speed a negative number. To move it left
or right, we would update the x instead of the y variable. To move the circle diagonally, we
would update both x and y at the same time.
Example 5-1 shows the complete code needed to create basic movement in a straight line.
Example 5-1. Moving in a straight line
<!doctype html>
<html
<html lang= "en" >
<head>
<head>
<meta
<meta charset= "UTF-8" >
<title>
<title> CH5EX1: Moving In A Straight Line </title>
</title>
< script src = "modernizr.js" >< /script>
< script type = "text/javascript" >
window . addEventListener ( 'load' , eventWindowLoaded , false
false );
function
function eventWindowLoaded () {
canvasApp ();
}
function
function canvasSupport () {
return
return Modernizr . canvas ;
}
function
function canvasApp () {
iif ( ! canvasSupport ()) {
return
return ;
}
function
function drawScreen () {
context . fillStyle = '#EEEEEE' ;
context . fillRect ( 0 , 0 , theCanvas . width , theCanvas . height );
//Box
context . strokeStyle = '#000000' ;
context . strokeRect ( 1 , 1 , theCanvas . width - 2 , theCanvas . height - 2 );
// Create ball
y += speed ;
context . fillStyle = "#000000" ;
context . beginPath ();
Search WWH ::




Custom Search