-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
71 lines (52 loc) · 1.57 KB
/
main.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function init() {
canvas.addEventListener("mousemove", function(event) {
mouseMoveListener(event);
}, false);
canvas.addEventListener('mouseup', function(event) {
mouseUpListener(event);
}, false);
canvas.addEventListener('mousedown', function(event) {
mouseDownListener(event);
}, false);
window.addEventListener("keyup", function(event) {
keyUpListener(event);
}, false);
tensionSlider.oninput = function() {
let cardinalSpline = new CardinalSpline();
cardinalSpline.setTension(this.value);
tensionValue.innerHTML = this.value;
}
setInterval(function() {
updateBoard();
}, 1000 / 32);
}
const pointArray = [];
function AddPoint(x, y) {
const isCloseFromOtherPoint = pointArray.some(function(point) {
if (point.checkClose(mousePoint))
return true;
return false;
});
if (isCloseFromOtherPoint)
return;
pointArray.push(new Point(x, y));
let cardinalSpline = new CardinalSpline()
cardinalSpline.updatePointArray(pointArray);
}
function DeletePoint(x, y) {
pointArray.some(function(point, idx) {
if (point.checkClose(mousePoint)) {
pointArray.splice(idx, 1);
let cardinalSpline = new CardinalSpline()
cardinalSpline.updatePointArray(pointArray);
return true;
}
return false;
});
}
function MovePoint(point, x, y) {
point.set(x, y);
let cardinalSpline = new CardinalSpline()
cardinalSpline.updatePointArray(pointArray);
}
init();