Hello its my frist time using canvas with this type of code… i don’t understand why the error happens, if you could help me know why this is not working… they say the agent could not be found on start of the read… anyway its trying all the time to have a solution . but it expend hours for me to nothing..
const randomRange = (min,max) => {
return Math.random() * (max - min) + min;
}
//code
var c = document.getElementById("canvastarget");
var width = c.offsetWidth
var height = c.offsetHeight
var context = c.getContext("2d");
//content
var numberofelements = 40
const agents = []
for (let index = 0; index < numberofelements; index++){
const x = randomRange(0, width)
const y = randomRange(0, height)
agents.push(new Agent(x, y))
}
//classes
class Point {
constructor(x,y){
this.x = x
this.y = y
}
}
class Agent{
constructor(x, y) {
this.pos = new Point(x,y)
this.radius = 10
}
draw(context) {
context.fillStyle = "black"
context.beginPath()
context.arc(this.pos.x,this.pos.y,this.radius,0,Match.PI * 2);
context.fill();
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<canvas id= canvastarget width = "1080px" height="1080px"></canvas>
</body>
</html>
The error is not clear for me its my first time doing class!