-
Notifications
You must be signed in to change notification settings - Fork 12
/
spline.html
224 lines (217 loc) · 4.78 KB
/
spline.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<!doctype html>
<!-- Copyright 2018 Raph Levien -->
<meta charset="utf-8">
<style>
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
svg {
touch-action: none;
}
.handle {
fill: none;
pointer-events: all;
}
/* including #handles is a hack to increase specificity */
#handles .handle:hover {
fill: #f00;
}
svg:hover .handle {
fill: #800;
}
svg:hover .selected .handle {
fill: #fcb;
stroke: black;
}
#handles line.target {
stroke: black;
}
#handles circle.target {
fill: none;
stroke: black;
stroke-opacity: 0.15;
stroke-width: 10;
}
svg:hover #handles line.tan {
stroke: #00f;
stroke-width: 1;
}
svg:hover #handles .tanhandle {
fill: white;
stroke: #00f;
}
svg:hover #handles .tanhandle.computed {
fill: rgba(255, 255, 255, 0.3);
stroke: rgba(0, 0, 255, 0.3);
}
svg:hover #handles .tanhandle:hover {
fill: #fcb;
}
#grid line {
stroke: #ddf;
}
#nav {
position: relative;
font-size: 12px;
/* float: left; */
height: 25px;
z-index: 10;
top: 0px;
left: 0;
padding: 0;
margin: 0;
width: 100%;
user-select: none;
}
#nav li {
float: left;
position: relative;
list-style: none;
}
#nav li a {
display: block;
padding: 5px 10px;
color: #000;
text-decoration: none;
cursor: default;
}
#nav a:hover:not(.inactive) {
background: #cdf;
}
#nav li ul {
position: absolute;
display: none;
background: #fff;
box-shadow: 2px 2px 5px 0 rgba(0, 0, 0, 0.3);
/*float: none;*/
}
#nav li ul a {
width: 10em;
width: -moz-max-content;
width: max-content;
padding: 4px 10px;
cursor: default;
}
#nav li ul a.inactive {
color: #888;
}
#nav li:hover ul {
display: block;
left: 0;
margin: 0;
padding: 0;
border-width: 1px;
border-style: solid;
border-color: #000;
}
#nav li:hover ul.off {
display: none;
}
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(255, 255, 255, 0.3);
}
.modal-content {
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 60%;
background-color: rgba(255, 255, 255, 0.8);
}
.modal-content pre {
white-space: pre-wrap;
}
.modal-content textarea {
width: 100%;
}
.modal-content button {
font-size: 14px;
}
.close {
float: right;
font-size: 28px;
user-select: none;
}
.close:hover, .close.focus {
cursor: pointer;
}
.invisible {
opacity: 0;
}
</style>
<body>
<ul id="nav">
<li><a href="#">File</a>
<ul>
<li><a id="menu-load">Load from JSON</a></li>
<li><a id="menu-save">Save to JSON</a></li>
</ul>
</li>
<li><a href="#">Edit</a>
<ul>
<li><a id="menu-delete">Delete point</a></li>
</ul>
</li>
<li><a href="#">View</a>
<ul>
<li><a id="menu-show-grid" href="#"><span id="show-grid-check">✓</span>
Show grid</a></li>
</ul>
</li>
<li><a href="#">Help</a>
<ul>
<li><a id="menu-help">About & help</a></li>
</ul>
</li>
</ul>
<div class="modal" id="help-modal">
<div class="modal-content">
<span class="close" id="help-close">×</span>
<p><b>A new spline</b></p>
<p>Add a new corner point: click. Add a new smooth point, Alt + click, or click and drag.</p>
<p>Select multiple points: Shift + click.</p>
<p>Refine a curve: click on the curve and drag.</p>
<p>Set an explicit tangent: click and drag on the handles. Set axis-aligned: Shift + click. Unset an explicit tangent: drag away.</p>
<p>Toggle between smooth and corner points: double-click.</p>
<p>Delete a point: delete (or backspace) key.
<p>Nudge points by 1 px: arrow keys. Nudge by 10 px: Shift + arrow keys.
<p>Copyright 2018 Raph Levien</p>
<p>Github repo: <a href="https://github.com/raphlinus/spline-research">raphlinus/spline-research</a></p>
</div>
</div>
<div class="modal" id="save-json-modal">
<div class="modal-content">
<span class="close" id="save-json-close">×</span>
<pre id="save-json-content"></pre>
</div>
</div>
<div class="modal" id="load-json-modal">
<div class="modal-content">
<span class="close" id="load-json-close">×</span>
<p><b>Load from JSON</b></p>
<textarea id="load-text" placeholder="Paste JSON data here..." rows=20></textarea>
<p><button id="load-button" type="button">Load</button></p>
</div>
</div>
<svg id="s" width="640" height="480" pointer-events="all">
<g id="grid" />
<path id="ctrlpoly" d="" stroke="none" fill="none" />
<path id="spline" d="" stroke="black" fill="none" stroke-width="2" />
<path id="spline2" d="" stroke="blue" fill="none" stroke-width="2" />
<g id="handles" />
<g id="plots" />
</svg>
</body>
<script src="bezpath.js"></script>
<script src="curves.js"></script>
<script src="biparabola.js"></script>
<script src="spiro.js"></script>
<script src="splineui.js"></script>