
previous

page 12
next
Now add the robot drawing function :
function one_step() {
fd(); g_k++;
if (g_k==g_numbers[g_j]) {
g_j++; g_k=0; rt();
}
if (g_j==5) {
g_i++; g_j=0
}
robot();
if (g_i<4) setTimeout(one_step,1000);
}
fd(); g_k++;
if (g_k==g_numbers[g_j]) {
g_j++; g_k=0; rt();
}
if (g_j==5) {
g_i++; g_j=0
}
robot();
if (g_i<4) setTimeout(one_step,1000);
}
Is this what you got?
Pretty but not quite what we're after!
But this is a reminder that working with canvas images is very different to our previous work where we could move images around after they'd been drawn.
Here we have to remove the old one before drawing the new one.
Catch is that the only way to remove the robot image is to clear the canvas and that will clear the spirolateral too!
So some real cleverness is called for and you'll have to wait for the next page to see what it is. Or are you smart enough to come up with a solution yourself?
previous
next