MCPcopy Index your code
hub / github.com/ChartGPU/ChartGPU / createWave

Function createWave

examples/chart-sync/main.ts:4–19  ·  view source on GitHub ↗
(
  count: number,
  opts: Readonly<{ phase: number; amplitude: number; fn: 'sin' | 'cos' }>
)

Source from the content-addressed store, hash-verified

2import type { ChartGPUOptions, DataPoint, ChartGPUInstance } from '../../src/index';
3
4const createWave = (
5 count: number,
6 opts: Readonly<{ phase: number; amplitude: number; fn: 'sin' | 'cos' }>
7): ReadonlyArray<DataPoint> => {
8 const n = Math.max(2, Math.floor(count));
9 const out: DataPoint[] = new Array(n);
10
11 for (let i = 0; i < n; i++) {
12 const t = i / (n - 1);
13 const x = t * Math.PI * 2;
14 const base = opts.fn === 'sin' ? Math.sin(x + opts.phase) : Math.cos(x + opts.phase);
15 out[i] = [x, base * opts.amplitude] as const;
16 }
17
18 return out;
19};
20
21const showError = (message: string): void => {
22 const el = document.getElementById('error');

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected