class Ball {
constructor({ id, x, y, radius, angle, speed, color, ctx }) {
this.id = id;
this.x = x || 10;
this.y = y || 10;
this.pos = [x ,y];
this.radius = radius || d3.randomUniform(3, 9)();
this.mass = radius * radius;
this.angle = angle || d3.randomUniform(0, 360)();
this.speed = speed || d3.randomUniform(1, maxSpeed)();
this.color = color || d3.schemeCategory10[Math.round(d3.randomUniform(0, 9)())];
this.ctx = ctx || null;
}
drawCircle() {
this.ctx.beginPath();
this.ctx.arc(this.x, this.y, this.radius, 0, 2 * Math.PI);
this.ctx.fillStyle = this.color;
this.ctx.stroke();
this.ctx.fill();
}
tick() {
[this.x, this.y] = this.pos = geometric.pointTranslate(this.pos, this.angle, this.speed);
}
}