-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
70 lines (60 loc) · 2.06 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>World Editor</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<h1>World Editor</h1>
<canvas id="myCanvas"></canvas>
<div id="controls">
<button onclick="dispose()">Clear</button>
<button onclick="save()">Save</button>
</div>
<script src="js/math/graph.js"></script>
<script src="js/math/primitives/polygon.js"></script>
<script src="js/math/primitives/envelope.js"></script>
<script src="js/viewport.js"></script>
<script src="js/items/tree.js"></script>
<script src="js/items/building.js"></script>
<script src="js/world.js"></script>
<script src="js/math/utils.js"></script>
<script src="js/math/graphEditor.js"></script>
<script src="js/math/primitives/point.js"></script>
<script src="js/math/primitives/segment.js"></script>
<script>
myCanvas.width = 600;
myCanvas.height = 600;
const ctx = myCanvas.getContext("2d");
const graphString = localStorage.getItem("graph");
const graphInfo = graphString ? JSON.parse(graphString) : null;
const graph = graphInfo?
Graph.load(graphInfo) :
new Graph();
const world = new World(graph);
const viewport = new Viewport(myCanvas);
const graphEditor = new GraphEditor(viewport, graph);
graph.draw(ctx);
let oldGraphHash = graph.hash();
animate();
function animate(){
viewport.reset();
if(graph.hash() != oldGraphHash){
world.generate();
oldGraphHash = graph.hash();
}
const viewpoint = scale(viewport.getOffset(), -1);
world.draw(viewpoint);
ctx.globalAlpha = 0.3;
graphEditor.display();
requestAnimationFrame(animate);
}
function dispose(){
graphEditor.dispose();
}
function save(){
localStorage.setItem("graph", JSON.stringify(graph));
}
</script>
</body>
</html>