Hong-Phuc Bui
2025-01-16 2889de7f0c2d587a17fbd322af57c29e84238620
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * draw-line.js
 *
 */
 
import {terminal} from "./lib/dfhi";
import * as JXG from "jsxgraph" ;
import {exportBoard, toggleAxis} from "./lib/dfhi-plot";
 
let board = undefined;
function initBoard() {
    return JXG.JSXGraph.initBoard("plotter", {
        boundingbox: [-1.5, 1.5, 1.5, -1.5], // left-top to right-bottom
        axis: true
    });
}
 
window.init = function() {
    board = initBoard();
    function exportSvg(event) {
        exportBoard(board);
    }
    document.getElementById("export").addEventListener("click", exportSvg);
    document.getElementById("axis")
        .addEventListener("click", (event)=> toggleAxis(board));
};
 
window.main = function(...argv) {
    let numOfPoint = Number.parseInt(argv[0]);
    if (board) {
        JXG.JSXGraph.freeBoard(board);
    }
    board = initBoard();
    const a = 3, b = 4, delta = Math.PI / 2;
    plotLissajousCurve(board,a, b, delta, numOfPoint);
};
 
function plotLissajousCurve(board, a, b, delta, numOfPoint) {
    terminal.printl("[DEBUG]-----------------");
    const SECTION_WIDTH = 2*Math.PI / numOfPoint;
    const A = 1, B = 1;
    for(let i = 0; i < numOfPoint; ++i) {
        let t = i * SECTION_WIDTH;
        let x = A* Math.cos(a*t + delta);
        let y = B* Math.sin(b*t);
        board.create('point', [x, y], {"withLabel":false, fillColor:"#00aa00"});
        terminal.printl({t, x, y});
    }
}