/* * 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}); } }