forked from Moddable-OpenSource/moddable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.js
33 lines (32 loc) · 938 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
import {Outline} from "commodetto/outline";
export default class extends Behavior {
onCreate(shape) {
this.count = 2;
shape.duration = 1000;
shape.bubble("onLabel", `PolygonPath`);
}
onFinished(shape) {
shape.time = 0;
shape.start();
}
onTimeChanged(shape) {
const count = 3 + Math.floor(shape.fraction * 9)
if (this.count != count) {
const cx = application.width >> 1;
const cy = application.height >> 1;
const r = Math.min(cx, cy) - 40;
const result = new Array();
const delta = 2 * Math.PI / count;
let angle = Math.PI / 2;
for (let i = 0; i < count; i++) {
result.push(cx + (r * Math.cos(angle)));
result.push(cy + (r * Math.sin(angle)));
angle += delta;
}
const path = Outline.PolygonPath(...result);
shape.fillOutline = Outline.fill(path);
shape.strokeOutline = Outline.stroke(path, 5, Outline.LINECAP_BUTT, Outline.LINEJOIN_MITER);
this.count = count;
}
}
}