From 0da400b126b4a008f0d4ba748665b4509cc5d95a Mon Sep 17 00:00:00 2001 From: Bill Rossi Date: Mon, 26 Jan 2026 16:59:07 -0500 Subject: [PATCH] Make clocks emptyable --- src/clock.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/clock.js b/src/clock.js index e73d787..543c664 100644 --- a/src/clock.js +++ b/src/clock.js @@ -23,7 +23,7 @@ class Clock { this.canvas.addEventListener("mousemove", event => { this.mouse.x = event.offsetX this.mouse.y = event.offsetY - this.mouseWedges = this.wedgeContainingMouse() + this.mouseWedges = this.wedgeContainingMouse() + 1 }) this.canvas.addEventListener("mouseup", event => { @@ -53,7 +53,14 @@ class Clock { ctx.fillRect(0, 0, this.canvas.width, this.canvas.height) ctx.lineWidth = 3 for (let i = 0; i < this.numWedges; i++) this.drawWedge(i) - if (this.mouse) { + if (this.mouse && this.mouseWedges == 0) { + ctx.fillStyle = "black" + ctx.beginPath() + ctx.arc(this.canvas.width / 2, this.canvas.height / 2, this.splitRadius, 0, Math.PI * 2) + ctx.fill() + } + + if (window.debug && this.mouse) { ctx.fillStyle = "black" ctx.beginPath() ctx.arc(this.mouse.x, this.mouse.y, 5, 0, Math.PI * 2) @@ -76,10 +83,10 @@ class Clock { ctx.stroke() if (this.mouseWedges != null) { - if (i < this.filledWedges && (i <= this.mouseWedges)) { + if (i < this.filledWedges && (i < this.mouseWedges)) { ctx.fillStyle = this.color ctx.fill() - } else if (i < this.filledWedges || (i <= this.mouseWedges)) { + } else if (i < this.filledWedges || (i < this.mouseWedges)) { ctx.fillStyle = this.hoverColor ctx.fill() } @@ -93,8 +100,12 @@ class Clock { wedgeContainingMouse() { if (!this.mouse) return false + const x = (this.canvas.width / 2) - this.mouse.x const y = (this.canvas.width / 2) - this.mouse.y + const distanceSquared = (x * x) + (y * y) + if (distanceSquared < (this.splitRadius * this.splitRadius)) return -1 + let theta = Math.atan2(y, x) - (Math.PI / 2) if (theta < 0) theta += Math.PI * 2 return Math.floor((theta / (2 * Math.PI)) * this.numWedges)