The Essential Guide to HTML5

(Greg DeLong) #1

CHAPTER 3


Code Explanation


var cwidth = 400;


var cheight = 300;


var ballrad = 10;


var boxx = 20;


var boxy = 30;


var boxwidth = 350;


var boxheight = 250;


var boxboundx = boxwidth+boxx-ballrad;


var boxboundy = boxheight+boxy-ballrad;


var inboxboundx = boxx+ballrad;


var inboxboundy = boxy+ballrad;


var ballx = 50;


var bally = 60;


var ctx;


var ballvx = 4;


var ballvy = 8;


function init(){


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


ctx.lineWidth = ballrad;


moveball();

Free download pdf