Share JSXGraph: example "Animation with setInterval"

JSXGraph
Share JSXGraph: example "Animation with setInterval"
This website is a beta version. The official release will be in **2023**.

Animation with setInterval

Have also a look at "Animation with requestAnimationFrame".
This example has been provided by user Cleonis.
<button onclick="play()">play</button> <button onclick="resetAnimation()">reset</button>
// Define the id of your board in BOARDID

const board = JXG.JSXGraph.initBoard(BOARDID, {
    boundingbox: [-1.5, 1.5, 1.5, -1.5],
    keepaspectratio: true,
    axis: true
});

var isPlaying = false;
var starttime = 0;
var timeElapsed = 0;
var interval;

var p = board.create('point',
    [() => Math.cos(timeElapsed), () => Math.sin(timeElapsed)]
);

function playing() {
    timeElapsed = (Date.now() - starttime) / 1000;
    board.update();
}

function play() {
    if (!isPlaying) {
        starttime = Date.now();
        isPlaying = true;
        interval = setInterval(playing, 50);
    }
}

function resetAnimation() {
    clearInterval(interval);
    timeElapsed = 0;
    isPlaying = false;
    board.update();
}