{
const groups = [];
const circle = `<circle id="camera" cx="100" cy="250" r="4" fill="white" stroke="black" />`;
const line = `<line x1="100" y1="250" x2="1000" y2="250" stroke="black" />`;
const circle2 = `<circle id="origin" cx="350" cy="250" r="4" fill="white" stroke="black" />`;
const debugText = `<text id="debug" x="10" y="20" fill="black">Interactive control</text>`;
const w = 700;
const h = 500;
const svgRef = svg`<svg style="background-color: white;" width="${w}" height="${h}" viewBox="0 0 ${w} ${h}">
${line}
${circle}
${circle2}
${debugText}
</svg>`;
const debugRef = svgRef.querySelector("#debug");
let ref = svgRef.querySelector("#camera");
let refLine = svgRef.querySelector("line");
let refOrigin = svgRef.querySelector("#origin");
function getCamera() {
return [ref.getAttribute("cx"), ref.getAttribute("cy")];
}
function getOrigin() {
return [refOrigin.getAttribute("cx"), refOrigin.getAttribute("cy")];
}
draggableElement({
element: ref,
callback: ([x, y]) => {
let p = 10;
x = Math.max(10, Math.min(700, x));
y = Math.max(0, Math.min(500, y));
ref.setAttribute("cx", x);
ref.setAttribute("cy", y);
refLine.setAttribute("x1", x);
refLine.setAttribute("y1", y);
const [ox, oy] = getOrigin();
let dx = ox - x;
let dy = oy - y;
dx *= 1000;
dy *= 1000;
refLine.setAttribute("x2", x + dx);
refLine.setAttribute("y2", y + dy);
},
defaultValue: [100, 250]
});
ref.addEventListener("mouseover", () => {
ref.setAttribute("fill", "lightgray");
ref.setAttribute("stroke-width", "2");
});
ref.addEventListener("mouseout", () => {
ref.setAttribute("fill", "white");
ref.setAttribute("stroke-width", "1");
});
return svgRef;
}