Recall that Math.random() returns a random number between 0 and 0.9999. When you multiply that result by myCanvas.width, you obviously end up with a number between zero and whatever the width of the canvas is. All good.
But also recall that the co-ordinates passed to ctx.drawImage specify the top-left corner of the image.
So if the x-position can be all the way over to the canvas width, the image might sometimes be drawn partly outside the visible canvas.
Now the watermelon is always completely visible.
|
|