dandiablo,
вы что-то не договариваете ...
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
#game {
border: 1px solid #8B4513;
}
</style>
</head>
<body>
<canvas height="300" width="300" id="game"></canvas>
<script>
const canvas = document.getElementById("game");
const ctx = canvas.getContext("2d");
const foodImg = new Image();
foodImg.src = "https://i.postimg.cc/QMgFDqpk/food.png";
let widthField = canvas.width;
let heightField = canvas.height;
let box = 32;
function drawGame() {
let food = {
x: Math.floor((Math.random() * (widthField - box))),
y: Math.floor((Math.random() * (heightField - box))),
width: box,
height: box
};
ctx.drawImage(foodImg, food.x, food.y, food.width, food.height);
}
let game = setInterval(drawGame, 1000);
</script>
</body>
</html>