forked from lennart-finke/knottingham
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
159 lines (139 loc) · 7.52 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> Knottingham 🪢</title>
<link rel="icon" href="https://fi-le.net/images/favicon.png">
<meta author content="fi-le">
<meta name="keywords" content="Knot Theory, Knottingham, Knots">
<script type="text/javascript" src="lib/paper.js"></script>
<script type="text/javascript" src="lib/BigInteger.min.js"></script>
<script type="text/javascript" src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<script type="text/javascript" src="js/polynomials.js"></script>
<script type="text/paperscript" canvas="canvas" src="js/canvas.js"></script>
</head>
<body>
<div style="text-align:center;">
<canvas id="canvas" width="1000px;" height="450px;"></canvas>
<div style="margin:5%;">
<div style="display: grid;grid-template-columns: 1.5fr 1fr;align-items: center;">
<p><b>Alexander Polynomial:</b> <span id="alexanderPolynomial"></span></p>
<div style="display: flex;align-items: center;">
<p><b>Candidates with \(<10\) Crossings:</b> </p><span id="candidates"></span>
</div>
</div>
<hr>
<p>
<button type="button" onclick="window.globals.draw(); smoothing.checked = false;"><b>Draw from Scratch</b></button>
<button type="button" onclick="window.globals.select()">Select / Unselect Bezier Handles</button>
<button type="button" onclick="window.globals.undo()">Undo</button>
</p>
<p>Force Smoothness: <input id="smoothing" type="checkbox" checked="true" onchange="window.globals.smooth = this.checked;">
| <button type="button" onclick="straighten()">Straighten</button>
</p>
<p>Drag Neighboring Points: <input id="dragging" type="checkbox" checked="false" onchange="window.globals.neighbors = this.checked ? 2 : 0;"> | <span style="color:grey;">Try reverting Non-Reidemeister moves (experimental):</span> <input type="checkbox" id="isomorphy" checked="false" onchange="window.globals.isomorphy = this.checked;"></p>
<p><b>Styling:</b><br>
Gap Width: <input type="range" min="2" max="5" value="2" class="slider" onchange="window.globals.gapWidth = this.value;"><br>
Stroke Width: <input type="range" min="1" max="10" value="3" class="slider" onchange="window.globals.strokeWidth = this.value; window.globals.updateStyle();"><br>
Show Intersections: <input type="checkbox" checked="true" onchange="window.globals.showIntersections = this.checked;">
</p>
<hr>
<p><b>Exporting:</b>
<button type="button" onclick="toSVG()">Export to SVG</button>
<button type="button" onclick="toJSON()">Export to JSON</button>
<button type="button" onclick="toTikz(); this.innerHTML='Export to TikZ (Copied to Clipboard!)'">Export to TikZ</button> <br>
<b>Importing JSON:</b> <input type="file" id="file" accept=".JSON,.json,.knottingham"name="Load a JSON file" oninput="readJSON(this.files[0])">
</p>
</div>
</div>
<div style="margin:5%;">
<h3>🪢🪢 Manual 🪢🪢</h3>
<p><b>Knottingham</b> is a tool that lets you draw and manipulate knot diagrams, sporting a clean yet somewhat hand-drawn look. To start knotting away, you may want to follow these steps:</p>
<ul>
<li>Create a knot by:</li>
<ul>
<li>Clicking on segments to add new nodes</li>
<li>Clicking and dragging nodes to move them (you can use 'Drag Neighbors' to rescue nodes from below crossings)</li>
<li>and finally <b>clicking on the (red) crossings to switch them.</b></li>
<li>or importing JSON</li>
<li><b>or clicking on 'Drawing' to draw a new knot from scratch</b>!</li>
</ul>
<li>Adjust the knot by:</li>
<ul>
<li>Removing nodes with <b>Shift+Click</b></li>
<li>Smoothing segments with <b>Control+Click</b></li>
<li>Moving, rotating and mirroring the knot with the <b>WASD+EQ+M</b> keys</li>
<li>Undoing with the <b>Z</b> key</li>
<li>Selecting it through the select button and adjust Bezier handles</li>
<li>Forcing smoothness (twice continuous differentiability, to be precise)</li>
<li>Adjusting the style with the sliders</li>
</ul>
<li> Show the knot to your friends by:
<ul>
<li>Exporting it to SVG!</li>
<li>Exporting it to JSON, to be imported back into Knottingham!</li>
<li>Exporting it to TikZ! (Fully customisable, but without crossing Info)</li>
</ul>
</li>
</ul>
These features are planned:
<ul>
<li>Complete Non-Reidemeister Move-Detection</li>
<li>Some more styling options</li>
</ul>
<p>Any and all feedback is appreciated! You can mail to <a href="mailto:developer/at/fi-le.net">developer/at/fi-le.net</a>. <br> Knottingham is open source - you can read and contribute to the code over <a href="https://github.com/file-acomplaint/knottingham">here</a>.</p>
</div>
<script type="text/javascript">
window.globals = {neighbors:0, strokeWidth:5, gapWidth:2, strokeColor:'black', showIntersections:true, smooth:true, isomorphy:false};
var polynomial = document.getElementById('alexanderPolynomial');
var candidates = document.getElementById('candidates');
var smoothing = document.getElementById('smoothing');
var dragging = document.getElementById('dragging');
var isomorphy = document.getElementById('isomorphy');
smoothing.checked = true; isomorphy.checked = false; dragging.checked = false;
function straighten() {
smoothing.checked = false;
window.globals.straighten();
}
function toTikz() {
var string = window.globals.toTikz();
navigator.clipboard.writeText(string);
}
function readJSON(file) {
const reader = new FileReader();
reader.onload = (e) => {
window.globals.fromJSON(e.target.result);
};
reader.readAsText(file);
}
function toSVG() {
// Kindly provided by users senz, Dave and defghi 1977
// https://stackoverflow.com/questions/23218174/how-do-i-save-export-an-svg-file-after-creating-an-svg-with-d3-js-ie-safari-an
var svg = window.globals.toSVG();
svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
var svgData = svg.outerHTML;
var preface = '<?xml version="1.0" standalone="no"?>\r\n';
var svgBlob = new Blob([preface, svgData], {type:"image/svg+xml;charset=utf-8"});
var svgUrl = URL.createObjectURL(svgBlob);
var downloadLink = document.createElement("a");
downloadLink.href = svgUrl;
downloadLink.download = "knottingham";
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
}
function toJSON() {
// Many thanks to users bformet and volzoran
// https://stackoverflow.com/questions/19721439/download-json-object-as-a-file-from-browser
var jsonString = window.globals.toJSON();
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(jsonString);
var dl = document.createElement("a");
dl.setAttribute("href", dataStr);
dl.setAttribute("download", "knot.knottingham");
dl.click();
document.body.removeChild(dl);
}
</script>
</body>
</html>