forked from Moddable-OpenSource/moddable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.js
38 lines (35 loc) · 883 Bytes
/
mod.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
import {Outline} from "commodetto/outline";
export default class extends Behavior {
onCreate(shape) {
const path = new Outline.CanvasPath();
path.moveTo(80, 60);
path.lineTo(240, 60);
path.moveTo(80, 120);
path.quadraticCurveTo(160, 200, 240, 120);
this.outlines = [
Outline.stroke(path, 20, Outline.LINECAP_BUTT),
Outline.stroke(path, 20, Outline.LINECAP_ROUND),
Outline.stroke(path, 20, Outline.LINECAP_SQUARE),
];
this.labels = [
"LINECAP_BUTT",
"LINECAP_ROUND",
"LINECAP_SQUARE",
];
this.index = -1;
shape.duration = 3000;
}
onFinished(shape) {
shape.time = 0;
shape.start();
}
onTimeChanged(shape) {
const c = this.outlines.length;
let i = Math.floor(c * shape.fraction);
if (i == c) i = c - 1;
if (this.index != i) {
shape.strokeOutline = this.outlines[i];
shape.bubble("onLabel", this.labels[i]);
}
}
}