The Essential Guide to HTML5

(Greg DeLong) #1

CHAPTER 8


Code Explanation


... = String(0);

(and it actually isn't necessary since
JavaScript will convert a number to a string in
this situation)

ctx = document.getElementById
('canvas').getContext('2d');


Set the variable to be used for all drawing

canvas1 = document.getElementById
('canvas');


Set the variable to be used for the mouse
click event handling

canvas1.addEventListener
('click',choose,false);


Set up click event handling

drawall(); Draw everything


ctx.font="bold 16pt Georgia"; Set the font to be used for the result
messages


ctx.fillStyle = "blue"; Set the color


} Close the function


function drawall() { Header for the function


ctx.clearRect(0,0,cwidth,cheight); Clear the canvas


var i; Variable for indexing


for (i=0;i<everything.length;i++) { Iterate through the everything array


everything[i].draw(); Draw the individual elements


} Close the for loop


} Close the function


Close the script element
Close the head element
Starting body tag. Set up call to the init
function
Free download pdf