-
Notifications
You must be signed in to change notification settings - Fork 2
/
triangle.js
55 lines (52 loc) · 1.55 KB
/
triangle.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class Triangle {
constructor(ax,ay,avecx,avecy,
bx,by,bvecx,bvecy,
cx,cy,cvecx,cvecy)
{
if (arguments.length == 0) {
this.ax = 0;
this.ay = 0;
this.avecx = 0;
this.avecy = 0;
this.bx = 0;
this.by = 0;
this.bvecx = 0;
this.bvecy = 0;
this.cx = 0;
this.cy = 0;
this.cvecx = 0;
this.cvecy = 0;
}
this.A = new Segment(ax,ay,avecx,avecy);
this.B = new Segment(bx,by,bvecx,bvecy);
this.C = new Segment(cx,cy,cvecx,cvecy);
this.set = (ax,ay,avec,avecy,
bx,by,bvecx,bvecy,
cx,cy,cvecx,cvecy) => {
this.ax = ax;
this.ay = ay;
this.avecx = avecx;
this.avecy = avecy;
this.bx = bx;
this.by = by;
this.bvecx = bvecx;
this.bvecy = bvecy;
this.cx = cx;
this.cy = cy;
this.cvecx = cvecx;
this.cvecy = cvecy;
}
this.color = "#fff";
this.draw = () => {
gfx.lineWidth = 1;
gfx.strokeStyle = this.color;
gfx.beginPath();
gfx.moveTo(grid.x + this.A.x, grid.y + this.A.y);
gfx.lineTo(grid.x + this.B.x, grid.y + this.B.y);
gfx.lineTo(grid.x + this.C.x, grid.y + this.C.y);
gfx.lineTo(grid.A + this.A.x, grid.y + this.A.y);
gfx.closePath();
gfx.fill();
}
}
};