Blog

Sine curves

This tool computes a curve of bytes for the CPC: a sum of sines, stretched from the minimum to the maximum. Choose the number of points, the range and the sines. A sine with a speed moves at each frame, and the preview animates the curve. The tool gives the RASM source that computes the bytes at assembly time, and the same bytes as db lines, ready to copy.

The tool needs JavaScript.

How it works

The curve has one value per point, numbered from 0 to points − 1. At point u, a sine is amplitude × sin(360 × k × u / points + phase), with the phase in degrees: k is the number of turns of the sine over the curve. The tool adds the sines, then stretches the sum: its smallest value becomes the minimum, its largest value the maximum. Each value is rounded to the nearest integer. The stretch sets the scale: only the ratios between the amplitudes count.

A negative minimum gives signed bytes, from −128 to 127. If not, the bytes go from 0 to 255. Settings that the tool refuses show with their cause, in place of the preview.

Speed

The speed scrolls a sine: at frame n, the CPC reads its table speed × n points further, and goes back to the start after the last point. Sines of the same speed share a table, and the "Table" column gives its name. When all the sines have the same speed, the source gives one table, from the minimum to the maximum.

With several speeds, the source gives one signed table per speed, and the constant <LABEL>_BASE. At each frame, the CPC adds the base and the value of each table at its position. Each table gets a whole span, in proportion to the span of its sines, and the spans add up to the span from the minimum to the maximum at most. Thus the curve stays in the range at every frame. It reaches the maximum only when the peaks of the tables meet.

Steps

The "Table of steps" box adds, for each table, the table of its steps: the step from each value to the next one, then the step from the last value back to the first. Each step must fit in a signed byte.

Output

The preview shows the values of the curve, its steps and, on request, each sine alone, at its speed. The RASM source computes the tables at assembly time, with the same rounding as the preview: RASM writes the bytes that the page shows. The db version gives these bytes already computed, with the same constants and the same labels. The address of the page keeps the settings: the link opens the same curve again, and the source quotes it in a comment.