In Javascript (Canvas) I want to draw an image in one of 4 random locations. I created 4 variables with an x and y value as shown:
var spawn1 = { x: -300, y: Math.floor(Math.random() * (canvas.height + 1)), } var spawn2 = { x: canvas.width + 300, y: Math.floor(Math.random() * (canvas.height + 1)), } var spawn3 = { x: Math.floor(Math.random() * (canvas.width + 1)), y: -300, } var spawn4 = { x: Math.floor(Math.random() * (canvas.width + 1)), y: canvas.height + 300, }
How would I go about picking one of these randomly and then using its x and y value to draw an image with those coordinates? I really don't know how to proceed from here, or if there's a better solution.