DGS Studio

2D Examples

Fourier Drawing

A heart drawn from separate X and Y cosine sums. Each term is [amplitude, frequency, phase]. Frequency 0 is a constant offset.

fourier_draw samples two cosine sums and plots the pairs (x(t), y(t)). Each coefficient is [amplitude, frequency, phase]. x(t) = Σ Aₙ cos(2π fₙ t + φₙ) and y(t) = Σ Bₙ cos(2π gₙ t + ψₙ). A frequency of 0 is a constant offset because the cosine no longer depends on t.

This heart uses a constant shift, then the sine terms written as cosines with phase −π/2, plus the four cosine terms of the classic heart. N = 512 is the allowed maximum; the lists are shorter, so every supplied term is drawn. t runs from 0 to 1, one closed period. The input is fourier_draw(.

Equation

fourier_draw(
  x_coefficients=[[1, 0, 0], [12, 1, -pi/2], [-4, 3, -pi/2]],
  y_coefficients=[[0.5, 0, 0], [13, 1, 0], [-5, 2, 0], [-2, 3, 0], [-1, 4, 0]],
  N=512,
  t_min=0,
  t_max=1
)

Graph preview

Graph preview of fourier_draw( x_coefficients=[[1, 0, 0], [12, 1, -pi/2], [-4, 3, -pi/2]], y_coefficients=[[0.5, 0, 0], [13, 1, 0], [-5, 2, 0], [-2, 3, 0]...
A static sample of this expression. The studio draws the full interactive result.

How a Fourier drawing is summed

A Fourier drawing gives x and y as separate cosine sums. One term is a triple [amplitude, frequency, phase]. The point at parameter t is the sum of amplitude · cos(2π · frequency · t + phase) on each axis. Frequency 0 does not oscillate: cos(phase) is constant, so that term shifts the whole drawing.

N is the maximum number of terms kept on each axis, up to 512. It is not a promise that the input listed exactly N triples, and it is not the number of samples. A handwritten list keeps its first N terms. A sum([amplitude, frequency, phase], n, start, end) expands the formulas to numbers, then keeps the strongest N amplitudes, including negative frequencies. source_x and source_y are sampled densely and converted with an FFT; each complex bin becomes one cosine term, amplitude |c| and phase arg(c), so sine and cosine parts both survive. Only significant bins are kept, and at most N of the strongest. The result lists requested N separately from the actual retained X and Y counts, because a band-limited curve needs fewer terms than the cap. Show Epicycles adds rotating circles and a guide line on the same board. The polyline stays. Play traces that finished path.

Reading the input

Try a change

Generate Graph samples the X and Y cosine sums and draws the polyline on the 2D board. The status panel separates requested N from the actual retained term counts and says whether the curve is direct/manual or FFT-generated. Show Epicycles can add rotating circles and a guide line. The X and Y scales match. Play traces the finished path.

Edit and generate

Generate Graph opens the studio homepage and runs this field. Open in DGS Studio loads the same text and waits for you to generate it. The equation is sent once, as a query parameter.

Related examples