-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
50 lines (43 loc) · 1.4 KB
/
index.html
File metadata and controls
50 lines (43 loc) · 1.4 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="styles.css">
<title>Graph Editor</title>
</head>
<body>
<h1>Graph Editor</h1>
<canvas id="myCanvas"></canvas>
<div id="controls">
<button onclick="dispose()">Clear</button>
<button onclick="save()">Save</button>
</div>
<script src="js/graphEditor.js"></script>
<script src="js/viewport.js"></script>
<script src="js/math/graph.js"></script>
<script src="js/math/utilities.js"></script>
<script src="js/primitives/point.js"></script>
<script src="js/primitives/segment.js"></script>
<script>
myCanvas.width = 600;
myCanvas.height = 600;
const ctx = myCanvas.getContext("2d");
const graphString = localStorage.getItem("graph");
const graphSaved = graphString ? JSON.parse(graphString) : null;
const graph = graphSaved ? Graph.load(graphSaved) : new Graph();
const viewport = new Viewport(myCanvas);
const graphEditor = new GraphEditor(viewport, graph);
animate();
function animate() {
viewport.reset();
graphEditor.display();
requestAnimationFrame(animate);
}
function dispose() {
graphEditor.dispose();
}
function save() {
localStorage.setItem("graph", JSON.stringify(graph));
}
</script>
</body>
</html>