the home site for me: also iteration 3 or 4 of my site

feat: add height input for arrow

Changed files
+28 -12
templates
shortcodes
+28 -12
templates/shortcodes/lensDiagram.html
···
<input type="number" id="objectDist" value="30" min="1" />
</div>
</div>
-
<div>
-
<label>Zoom:</label>
-
<input
-
type="range"
-
id="zoom"
-
min="0.01"
-
max="8"
-
step="0.01"
-
value="1"
-
style="width: 100%"
-
/>
+
<div style="display: flex; gap: 20px; align-items: center; width: 100%">
+
<div>
+
<label>Object Height:</label>
+
<input
+
type="number"
+
id="objectHeight"
+
value="20"
+
min="0.1"
+
step="0.1"
+
/>
+
</div>
+
<div style="flex: 1">
+
<label>Zoom:</label>
+
<input
+
type="range"
+
id="zoom"
+
min="0.01"
+
max="8"
+
step="0.01"
+
value="1"
+
style="width: 100%"
+
/>
+
</div>
</div>
</div>
<canvas id="canvas" style="flex: 1; cursor: move"></canvas>
···
const mirrorType = document.getElementById("mirrorType");
const radiusInput = document.getElementById("radius");
const objectDistInput = document.getElementById("objectDist");
+
const objectHeightInput = document.getElementById("objectHeight");
const zoomInput = document.getElementById("zoom");
+
+
objectHeightInput.value = Math.round(radiusInput.value / 3);
let offsetX = 0;
let offsetY = 0;
···
function drawRays(isConcave, R, objDist) {
const scale = (canvas.width / (R * 6)) * parseFloat(zoomInput.value);
const F = R / 2;
-
const h = (R * scale) / 3;
+
const h = parseFloat(objectHeightInput.value) * scale;
const centerX = canvas.width / 2 + R * scale + offsetX;
const centerY = canvas.height / 2 + offsetY;
const objX =
···
mirrorType.addEventListener("change", update);
radiusInput.addEventListener("input", update);
objectDistInput.addEventListener("input", update);
+
objectHeightInput.addEventListener("input", update);
zoomInput.addEventListener("input", update);
window.addEventListener("resize", update);