previous

page 11

next
function test() {
g_i=0; g_j=0; g_k=0;
one_step();
}

Perhaps you thought it wasn't working properly? This is because there are times when the robot is going over the same lines and so we don't see any change.

So it's time to actually show the robot. You can use my images or create your own.

And here's how we draw an image on the canvas:

g_ctx.drawImage(img,x,y);

It's best to load the images beforehand so add this to your globals.js:

var g_img=[];
for (var i=0;i<4;i++) {
g_img[i]=new Image();
g_img[i].src='images/'+i+'.png';
}

And this to my.js:

function robot() {
var i=g_h/90;
var w2=g_img[0].width/2;
g_ctx.drawImage(g_img[i],g_x-w2,g_y-w2);
}
previous
next