-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rectangle.js
41 lines (36 loc) · 1.03 KB
/
Rectangle.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
var Rectangle = function(x,y,width,height,color,fill) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.color = color;
this.fill = fill;
}
Rectangle.prototype.draw = function (context) {
if (this.fill) {
this.strokeFillDraw(context);
} else {
this.strokeDraw(context);
}
}
Rectangle.prototype.strokeDraw = function (context) {
var f = Math.floor;
context.fillStyle = this.color;
context.strokeRect(f(this.x), f(this.y), f(this.width), f(this.height));
}
Rectangle.prototype.fillDraw = function (context) {
var f = Math.floor;
context.fillStyle = this.color;
context.fillRect(f(this.x), f(this.y), f(this.width), f(this.height));
}
Rectangle.prototype.strokeFillDraw = function (context) {
var f = Math.floor;
context.fillStyle = "rgb(0,0,0)";
context.fillRect(f(this.x), f(this.y), f(this.width), f(this.height));
context.fillStyle = this.color;
context.fillRect(f(this.x+1), f(this.y+1), f(this.width-2), f(this.height-2));
}
Rectangle.prototype.move = function(dx, dy) {
this.x += dx;
this.y += dy;
}