-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormals.js
47 lines (41 loc) · 835 Bytes
/
normals.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
let normals = [];
function drawNormals() {
const nbOfLines = 20;
const length = 10;
for (let i = 0; i < nbOfLines; i++) {
const t = i / nbOfLines;
const from = {
x: curve.mx(t),
y: curve.my(t),
};
const normal = curve.mNormal(t);
const to = {
x: from.x + normal.x * length,
y: from.y + normal.y * length
};
const line = new fabric.Line([from.x, from.y, to.x, to.y], {
fill: '',
stroke: 'red',
strokeWidth: 1
});
canvas.add(line);
normals.push(line);
}
}
function toggleNormals() {
if (normals.length) {
removeNormals();
normals.length = 0;
} else {
drawNormals();
}
}
function removeNormals() {
normals.forEach(line => {
canvas.remove(line);
});
}
function redrawNormals() {
removeNormals();
drawNormals();
}