-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanvas.js
37 lines (29 loc) · 893 Bytes
/
canvas.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
var canvas = document.getElementById ("canvas");
var context = canvas.getContext ("2d");
export class Square {
x;
y;
width;
color;
constructor (x, y, width, color = "black") {
this.x = x;
this.y = y;
this.width = width;
this.color = color;
}
draw () {
context.fillStyle = this.color;
context.fillRect (canvas.width / 2 + this.x - this.width / 2, canvas.height / 2 - this.y - this.width / 2, this.width, this.width);
}
}
export class Rectangle extends Square {
height;
constructor (x, y, width, height, color = "black") {
super (x, y, width, color);
this.height = height;
}
draw () {
context.fillStyle = this.color;
context.fillRect (canvas.width / 2 + this.x - this.width / 2, canvas.height / 2 - this.y - this.height / 2, this.width, this.height);
}
}