MCPcopy
hub / github.com/ChartGPU/ChartGPU / createSineWave

Function createSineWave

examples/basic-line/main.ts:11–28  ·  view source on GitHub ↗
(
  count: number,
  opts?: Readonly<{ phase?: number; amplitude?: number }>
)

Source from the content-addressed store, hash-verified

9import type { GridArea } from '../../src/renderers/createGridRenderer';
10
11const createSineWave = (
12 count: number,
13 opts?: Readonly<{ phase?: number; amplitude?: number }>
14): ReadonlyArray<DataPoint> => {
15 const n = Math.max(2, Math.floor(count));
16 const out: DataPoint[] = new Array(n);
17 const phase = opts?.phase ?? 0;
18 const amplitude = opts?.amplitude ?? 1;
19
20 for (let i = 0; i < n; i++) {
21 const t = i / (n - 1);
22 const x = t * Math.PI * 2;
23 const y = Math.sin(x + phase) * amplitude;
24 out[i] = [x, y] as const;
25 }
26
27 return out;
28};
29
30const showError = (message: string): void => {
31 const el = document.getElementById('error');

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected