previous

page 14

next
function setup() {
g_side=45*vmin();
var canvas=document.getElementById('c');
canvas.width=g_side; canvas.height=g_side;
g_ctx=canvas.getContext('2d');
canvas=document.getElementById('robot');
canvas.width=g_side; canvas.height=g_side;
g_robot=canvas.getContext('2d');
g_x0=g_side/2; g_y0=g_side*.75;
g_step=g_side/8;
home();
}
function robot() {
g_robot.clearRect(0,0,g_side,g_side);
var i=g_h/90;
var w2=g_img[0].width/2;
g_robot.drawImage(g_img[i],g_x-w2,g_y-w2);
}

Before pushing on, let me deal with another of the gotchas that I've encountered. My iPad throws up the resize trigger even when there's no resize so the picture disappears almost immediately.

This is my solution:

<body onResize='resize();'>

This function only calls setup() if the size has actually changed.

previous
next