mardi 6 avril 2021

How to move a rectangle every 5 second in javascript cavas?

I need to move a rectangle in a random position every 5 seconds, I have this

function rectangle(x,y){
var ctx
ctx.beginPath();
ctx.rect(20, 20, 15, 10);
ctx.stroke();
}
function randomMove(){
var myVar;
var x;
var y;
myVar = setInterval( , 5000);
x = Math.floor(Math.random() * 10) + 1;
y = Math.floor(Math.random() * 10) + 1;
rectangle(x,y)
}

I don't know what to add in the setInterval next to the 5000, what should I add to make it work?




Aucun commentaire:

Enregistrer un commentaire