Light up a clicked orbit so it is not dimmed by the previous hover
1 changed file+25−10
app/main.jsmodified+25−10View file
@@ -2345,32 +2345,39 @@ function createExplorer({ id, listen = false }) {
23452345 if (!view) return;
23462346 const [t2, p2] = eventPoint(e);
23472347 if (Math.abs(t2) > Math.PI) return;
2348- // listening: a click on an orbit plays it, and a click elsewhere starts
2349- // a new orbit and plays that
2350- const near = listener && orbitNear(t2, p2);
2348+ // the clicked orbit lights up, and stays lit until the mouse moves away
2349+ // (otherwise the orbit that was under the mouse stays lit, and dims the
2350+ // new one to almost nothing)
2351+ clickAt = [e.clientX, e.clientY];
2352+ // listening: a click on an orbit's dots plays it, and a click elsewhere
2353+ // starts a new orbit and plays that
2354+ const near = listener && orbitNear(t2, p2, 1);
23512355 if (near) {
23522356 selected = near;
2357+ setHovered(near);
23532358 listener.play(near.start);
23542359 return;
23552360 }
23562361 setAuto(false);
23572362 const o = addOrbit(t2, p2);
2358- if (o && listener) {
2363+ if (!o) return;
2364+ setHovered(o);
2365+ if (listener) {
23592366 selected = o;
23602367 listener.play(o.start);
23612368 }
23622369 });
23632370
2364- // the orbit with a dot in the nearest cell within 3 cells of (t2, p2)
2365- function orbitNear(t2, p2) {
2371+ // the orbit with a dot in the nearest cell within r cells of (t2, p2)
2372+ function orbitNear(t2, p2, r = 3) {
23662373 if (Math.abs(t2) > gridThetaMax + 0.1 || Math.abs(p2) > gridPMax * 1.05) return null;
23672374 const c0 = cellOf(t2, p2);
23682375 const i0 = c0 % gx;
23692376 const j0 = (c0 - i0) / gx;
23702377 let best = null;
23712378 let bestD = Infinity;
2372- for (let dj = -3; dj <= 3; dj++) {
2373- for (let di = -3; di <= 3; di++) {
2379+ for (let dj = -r; dj <= r; dj++) {
2380+ for (let di = -r; di <= r; di++) {
23742381 const i = i0 + di;
23752382 const j = j0 + dj;
23762383 if (i < 0 || i >= gx || j < 0 || j >= gy) continue;
@@ -2397,10 +2404,18 @@ function createExplorer({ id, listen = false }) {
23972404 }
23982405 }
23992406
2407+ // where the last click was, in client pixels, until the mouse leaves it
2408+ let clickAt = null;
24002409 canvas.addEventListener('mousemove', (e) => {
2401- if (view) setHovered(orbitNear(...eventPoint(e)));
2410+ if (!view) return;
2411+ if (clickAt && Math.hypot(e.clientX - clickAt[0], e.clientY - clickAt[1]) < 12) return;
2412+ clickAt = null;
2413+ setHovered(orbitNear(...eventPoint(e)));
2414+ });
2415+ canvas.addEventListener('mouseleave', () => {
2416+ clickAt = null;
2417+ setHovered(null);
24022418 });
2403- canvas.addEventListener('mouseleave', () => setHovered(null));
24042419
24052420 autoButton.addEventListener('click', () => {
24062421 stopGpu();