Dear Colin,
interesting challenge! This could be a starter:
const board = JXG.JSXGraph.initBoard('jxgbox', {
boundingbox: [-5, 5, 5, -5], axis: true
});
var clicks = [];
var A = board.create('point', [2, 2]);
var B = board.create('point', [2, -2]);
board.on('click', function (evt) {
// Get all elements under mouse pointer + position
let list = this.getAllUnderMouse(evt);
if (clicks.length === 0) {
// Add point
if (list.length > 1 && JXG.isPoint(list[0])) {
clicks.push(list[0]);
list[0].setAttribute({ color: JXG.palette.blue });
}
} else {
// Point has been selected, now get the
// new position for the point
if (list.length === 1) {
let pos = list[0];
let point = clicks[0];
point.moveTo(
[Math.round(pos[0]), Math.round(pos[1])],
500,
{
callback: function () {
point.setAttribute({ color: JXG.palette.red });
}
}
);
clicks = [];
}
}
});
Best wishes, Alfred