-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
107 lines (92 loc) · 3.32 KB
/
index.html
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Complex Fourier Series Animation</title>
<script src="elm.js"></script>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-light bg-light">
<a class="navbar-brand" href="#">Complex Fourier Series Animation</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Animation <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/Aurelius333/complex-fourier-series-animation">GitHub</a>
</li>
</ul>
</div>
</nav>
<div id="elm"></div>
<script>
"use strict";
var app = Elm.Main.init({
node: document.getElementById('elm')
});
function getMousePosition(svg, e) {
let point = svg.createSVGPoint()
point.x = e.clientX
point.y = e.clientY
return point.matrixTransform(svg.getScreenCTM().inverse())
}
function subtractSvgPoints(svg, p1, p2) {
let ret = svg.createSVGPoint()
ret.x = p1.x - p2.x
ret.y = p1.y - p2.y
return ret
}
let dragging = false
let oldMousePos
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
{
let svg = document.getElementById("drawable-svg")
if (svg) {
svg.addEventListener('mousemove', (e) => {
let position = getMousePosition(svg, e)
let event = new CustomEvent("svgmousemove", { detail: position })
svg.dispatchEvent(event)
})
}
}
{
let svg = document.getElementById("draggable-svg")
if (svg) {
function startDrag(evt) {
dragging = true
oldMousePos = getMousePosition(svg, evt)
}
function drag(evt) {
if (dragging) {
let position = getMousePosition(svg, evt)
let difference = subtractSvgPoints(svg, oldMousePos, position)
console.log(difference)
let event = new CustomEvent("svgdrag", { detail: difference })
svg.dispatchEvent(event)
oldMousePos = position
}
}
function endDrag(evt) {
dragging = false
}
svg.addEventListener('mousedown', startDrag);
svg.addEventListener('mousemove', drag);
svg.addEventListener('mouseup', endDrag);
svg.addEventListener('mouseleave', endDrag);
}
}
});
});
observer.observe(document.body, { childList: true, subtree: true });
</script>
</body>
</html>