Skip to content

Commit 56d26ba

Browse files
committed
Better UI
1 parent bd4e9fc commit 56d26ba

File tree

1 file changed

+38
-21
lines changed

1 file changed

+38
-21
lines changed

examples/canvas/interpolation/index.html

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,30 @@
1717
x4;y4
1818
"
1919
>
20-
-3.24;0.8
21-
-0.88;3.77
22-
1.5;3.47
23-
2.6;5.66
24-
4.15;7.86
25-
5.7;8.02
26-
7.52;9.75
20+
-3.24;0.8
21+
-0.88;3.77
22+
1.5;3.47
23+
5.7;8.02
24+
7.52;9.75
2725
</textarea
2826
>
29-
<!--
30-
8.44;11.46
31-
9.63;11.15
32-
10.58;12.63
33-
11.54;14.74
34-
12.7;12.86 -->
35-
<button id="interpolateButton">Interpolate!</button>
36-
<button id="stopButton">Stoooooop!</button>
27+
<div style="display: flex; flex-direction: column; gap: 20px; width: 200px">
28+
<button id="interpolateButton">Interpolate!</button>
29+
<button id="stopButton">Stoooooop!</button>
30+
<label>Lower bound:</label>
31+
<div style="display: flex; justify-content: space-between; align-items: center">
32+
<input type="range" step="0.1" min="-10" max="0" value="-10" id="lowerSlider" />
33+
<strong id="lowerView" style>-10</strong>
34+
</div>
35+
<label>Upper bound:</label>
36+
<div style="display: flex; justify-content: space-between; align-items: center">
37+
<input type="range" step="0.1" min="0" max="10" value="10" id="upperSlider" />
38+
<strong id="upperView" style>10</strong>
39+
</div>
40+
</div>
3741
</div>
3842

39-
<canvas id="wasmCanvas" width="2000px" height="2000px"></canvas>
43+
<canvas id="wasmCanvas" width="1000px" height="1000px" style="border: black solid 1px"></canvas>
4044

4145
<script type="module">
4246
import { getLameWasmEnv, lamePostInit } from "../../../lib/lamelib.js";
@@ -77,14 +81,14 @@
7781
}
7882

7983
const FF_SCALE = 1000;
80-
const LOWER_BOUND = -4;
81-
const UPPER_BOUND = 10;
84+
let lowerBound = -10;
85+
let upperBound = 10;
8286
const MILLISECONDS_IN_SECOND = 1000;
8387

8488
let stop = false;
8589
let start;
8690
let previous;
87-
const MAX_STEPS = 1000;
91+
const MAX_STEPS = 2000;
8892
let steps = MAX_STEPS;
8993

9094
function next(timestamp) {
@@ -100,7 +104,7 @@
100104

101105
const ts = (timestamp - start) / MILLISECONDS_IN_SECOND; // second == 1 on x-axis
102106
console.log(ts);
103-
if (ts > UPPER_BOUND) {
107+
if (ts > upperBound) {
104108
console.log("Reached upper bound");
105109
return;
106110
}
@@ -122,10 +126,11 @@
122126
}
123127

124128
function interpolate() {
129+
stop = false;
125130
steps = MAX_STEPS;
126131
ctx.clearRect(0, 0, 1000, 1000);
127132
window.requestAnimationFrame((timestamp) => {
128-
start = timestamp - LOWER_BOUND * MILLISECONDS_IN_SECOND;
133+
start = timestamp - lowerBound * MILLISECONDS_IN_SECOND;
129134
window.requestAnimationFrame(next);
130135
});
131136
}
@@ -135,6 +140,18 @@
135140
document.getElementById("stopButton").addEventListener("click", () => {
136141
stop = true;
137142
});
143+
144+
const lowerView = document.getElementById("lowerView");
145+
document.getElementById("lowerSlider").addEventListener("input", (event) => {
146+
console.log(event.target.value);
147+
lowerBound = event.target.value;
148+
lowerView.innerHTML = lowerBound;
149+
});
150+
151+
document.getElementById("upperSlider").addEventListener("input", (event) => {
152+
upperBound = event.target.value;
153+
upperView.innerHTML = upperBound;
154+
});
138155
</script>
139156
</body>
140157
</html>

0 commit comments

Comments
 (0)