This repository has been archived by the owner on Nov 14, 2021. It is now read-only.
/
CanvasParticleWay.ts
74 lines (63 loc) · 1.59 KB
/
CanvasParticleWay.ts
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { ParticleWay } from "particle-waypoint";
import Container = createjs.Container;
import Shape = createjs.Shape;
export class CanvasParticleWay extends ParticleWay {
private passage: Shape;
private passageColor: string = "rgba(255, 0, 0, 0.25)";
constructor(
points: number[][],
option?: {
parent?: Container;
passageColor?: string;
}
) {
super(points);
if (!option) return;
if (option.passageColor) {
this.passageColor = option.passageColor;
}
if (option.parent) {
this.initPassage(option.parent);
}
}
private initPassage(parent: Container): void {
if (this.passage) return;
this.passage = new Shape();
this.passage.visible = false;
parent.addChild(this.passage);
this.drawPassage();
}
protected onSetPoints() {
super.onSetPoints();
this.drawPassage();
}
private drawPassage(): void {
if (!this.passage) return;
if (!this.points) return;
if (this.points.length <= 1) return;
const isBezier = this.points[1].length === 6;
const g = this.passage.graphics;
g.clear();
g.ss(1).beginStroke(this.passageColor);
this.points.forEach((p, index) => {
if (index === 0) {
g.mt(p[0], p[1]);
return;
}
if (!isBezier) {
g.lt(p[0], p[1]);
return;
}
g.bezierCurveTo(p[0], p[1], p[2], p[3], p[4], p[5]);
});
g.ef();
}
public showPassage(): void {
if (!this.passage) return;
this.passage.visible = true;
}
public hidePassage(): void {
if (!this.passage) return;
this.passage.visible = false;
}
}