-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBall.js
34 lines (34 loc) · 788 Bytes
/
Ball.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function Ball(radius, color) {
if (typeof radius === 'undefined') {
radius = 40;
}
if (typeof color === 'undefined') {
color = '#FF0000';
}
this.x = 0;
this.y = 0;
this.vx = 0;
this.vy = 0;
this.radius = radius;
this.color = color;
this.scaleX = 1;
this.scaleY = 1;
this.rotation = 0;
this.lineWidth = 1;
}
Ball.prototype.draw = function (context) {
context.save();
context.translate(this.x, this.y);
context.rotate(this.rotation);
context.scale(this.scaleX, this.scaleY);
context.lineWidth = this.lineWidth;
context.fillStyle = this.color;
context.beginPath();
context.arc(0, 0, this.radius, 0, (Math.PI * 2), true);
context.closePath();
context.fill();
if (this.lineWidth > 0) {
context.stroke();
}
context.restore();
};