Skip to content

Instantly share code, notes, and snippets.

@alicethewhale
Created December 14, 2018 11:31
Show Gist options
  • Save alicethewhale/527546af9046b463274c7838c44c3d25 to your computer and use it in GitHub Desktop.
Save alicethewhale/527546af9046b463274c7838c44c3d25 to your computer and use it in GitHub Desktop.
let startX = 0;
let startY = 0;
const mainTree = document.querySelector(".main-tree");
function startTinsel(e) {
if (decSelector.value === "tinsel") {
startX = e.clientX - 58;
startY = e.clientY - 82;
}
}
function endTinsel(e) {
if (decSelector.value === "tinsel") {
const tinsel = document.createElementNS("http://www.w3.org/2000/svg", 'path');
let endX = e.clientX - 58;
let endY = e.clientY - 82;
tinsel.classList.add("tinsel");
tinsel.setAttribute("d", `M ${startX},${startY} C ${startX},${startY+18} ${endX},${endY+18} ${endX},${endY} `);
mainTree.appendChild(tinsel);
}
}
triangles.forEach(triangle => triangle.addEventListener('mousedown', startTinsel));
triangles.forEach(triangle => triangle.addEventListener('mouseup', endTinsel));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment