forked from edwardzhong/html5Canvas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathball.js
41 lines (38 loc) · 973 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
35
36
37
38
39
40
41
function Ball(radius,color){
this.x = 0;
this.y = 0;
this.vx = 0;
this.vy = 0;
this.radius = radius||20;
this.rotation = 0;
this.mass = 1;
this.scaleX = 1;
this.scaleY = 1;
this.name = "";
this.color = color||'#ff0000';
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.strokeStyle = this.color;
context.beginPath();
context.arc(0,0,this.radius,0,Math.PI*2,false);
context.closePath();
context.fill();
context.stroke();
context.restore();
}
//得到球体的左上角坐标
Ball.prototype.getBounds = function(){
return {
x: this.x - this.radius,
y: this.y - this.radius,
width: this.radius*2,
height: this.radius*2
};
}