-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9780df
commit 28a113b
Showing
2 changed files
with
29 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,50 @@ | ||
export class Shape { | ||
constructor(x, y, col) { | ||
this.x = x; | ||
this.y = y; | ||
this.col = col; | ||
this._x = x; | ||
this._y = y; | ||
this._col = col; | ||
} | ||
|
||
get x() { | ||
return this._x; | ||
} | ||
|
||
set x(val) { | ||
if (typeof val !== 'number') { | ||
throw new TypeError('x must be a number'); | ||
} | ||
this._x = val; | ||
} | ||
|
||
moveBy(x, y) { | ||
this.x += x; | ||
this.y += y; | ||
this._x += x; | ||
this._y += y; | ||
} | ||
} | ||
|
||
export class Rectangle extends Shape { | ||
constructor(x, y, width, height, col) { | ||
super(x, y, col); | ||
this.width = width; | ||
this.height = height; | ||
this._width = width; | ||
this._height = height; | ||
} | ||
|
||
draw(ctx) { | ||
ctx.fillStyle = this.col; | ||
ctx.fillRect(this.x, this.y, this.width, this.height); | ||
ctx.fillStyle = this._col; | ||
ctx.fillRect(this._x, this._y, this._width, this._height); | ||
} | ||
} | ||
|
||
export class Circle extends Shape { | ||
constructor(x, y, r, col) { | ||
super(x, y, col); | ||
this.r = r; | ||
this._r = r; | ||
} | ||
|
||
draw(ctx) { | ||
ctx.fillStyle = this.col; | ||
ctx.fillStyle = this._col; | ||
ctx.beginPath(); | ||
ctx.arc(this.x, this.y, this.r, 0, 2 * Math.PI); | ||
ctx.arc(this._x, this._y, this._r, 0, 2 * Math.PI); | ||
ctx.fill(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters