antigrav_lab/js/data.js

23 lines
576 B
JavaScript

/**
* Generates sine wave data.
* Attached to window to avoid ES Module CORS issues on file:// protocol.
*/
(function (global) {
global.DataGenerator = {
generateSineWave(points = 100, cycles = 2 * Math.PI) {
const labels = [];
const data = [];
for (let i = 0; i <= points; i++) {
const x = (i / points) * cycles;
const y = Math.sin(x);
labels.push(x.toFixed(2));
data.push(y);
}
return { labels, data };
}
};
})(window);