From a56fac5bfd870ce4c2f5bf4fb1dad2e15b038865 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Thu, 17 Dec 2020 12:12:37 +0100 Subject: [PATCH] little cleanup --- js/game.js | 6 ------ js/svg.js | 13 +++---------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/js/game.js b/js/game.js index b541931..f8237bb 100644 --- a/js/game.js +++ b/js/game.js @@ -30,12 +30,6 @@ export function init(svgEl, crosshairXEl, crosshairYEl) { let shapeEl = document.createElementNS('http://www.w3.org/2000/svg', 'path'); shapeEl.classList.add('rect'); let p1 = { 'x': mousedownEv.clientX - rect.left, 'y': mousedownEv.clientY - rect.top } - // shapeEl.setAttribute('x', p1.x); - // shapeEl.setAttribute('y', p1.y); - - // shapeEl.setAttribute('width', 0); - // shapeEl.setAttribute('height', 0); - let d = getPathShapeBetweenPoints(p1, p1, segmentCount); svgEl.appendChild(shapeEl); shapeEl.setAttribute('d', d); diff --git a/js/svg.js b/js/svg.js index df6d4a2..b0acd2b 100644 --- a/js/svg.js +++ b/js/svg.js @@ -2,13 +2,7 @@ function getPathShapeBetweenPoints(p1, p2, corners) { let d = `M ${p1.x},${p1.y} L `; if(corners == 4){ - // draw inbetween p1 & p2. - let minx = Math.min(p1.x, p2.x); - let miny = Math.min(p1.y, p2.y); - let maxx = Math.max(p1.x, p2.x); - let maxy = Math.max(p1.y, p2.y); - d += ` ${p1.x},${p2.y} ${p2.x},${p2.y} ${p2.x},${p1.y} ${p1.x},${p1.y} `; } else{ @@ -19,7 +13,8 @@ function getPathShapeBetweenPoints(p1, p2, corners) { const length = Math.sqrt(Math.pow(p1.x-p2.x,2)+ Math.pow(p1.y - p2.y, 2)); const segmentAngle = Math.PI * 2 / corners; - // we don't want + // TODO: can we find a way to draw not from the first 3 segments, but have the + // cursor span as many segment as possible // const segmentsAngle = Math.floor(180/segmentAngle) * segmentAngle; const radius = (length*.5)/Math.sin(segmentAngle); @@ -38,9 +33,7 @@ function getPathShapeBetweenPoints(p1, p2, corners) { let startRot = Math.asin(sx / radius); if(sy>0){startRot = -1 * startRot + Math.PI;} - // console.log(sx, radius, startRot); - // animI+= .1; - // console.log(sx, sy, startRot); + for (let a = 0; a < Math.PI*2; a += segmentAngle) { let x = radius * Math.sin(a-startRot) + cx; let y = radius * Math.cos(a-startRot) + cy;