Declaring a parameter is how a sketch hands the performer something to play. Declare once at startup, then read the live values every frame.
sialk.parameters.declare({
speed: { type: 'number', min: 0, max: 4, default: 1, label: 'Speed' },
glow: { type: 'number', min: 0, max: 1, default: 0.3 },
invert: { type: 'boolean', default: false },
mode: { type: 'enum', options: ['rings', 'bars', 'dust'], default: 'rings' },
tint: { type: 'colour', default: '#ffbb66' },
burst: { type: 'trigger' },
});
Every one of those becomes a control on the surface:
| You declare | The performer gets |
|---|---|
number |
a fader |
boolean |
a toggle |
enum |
buttons |
colour |
a swatch |
trigger |
a FIRE button |
Reading them
sialk.parameters.values is the same object for your sketch's whole life,
mutated in place. Read from it in your draw loop:
function draw() {
const p = sialk.parameters.values;
background(0);
rotate(frameCount * 0.01 * p.speed);
if (p.invert) filter(INVERT);
}
Do not destructure it once at startup and hold the values, you will read the defaults forever.
Give every number a min and a max
A fader needs to know its ends. A number with no range cannot become one, and the control is what you are declaring the parameter for.
The range is also what modulation reads: reach is expressed in the parameter's own units, so a sensible min and max is what makes a modulator usable rather than a guess. See modulation.
Label them
label is what a performer reads at a dark desk, possibly having never met your
sketch. glow is a variable name; Glow amount is a label. It costs nothing
and it is the difference between a surface someone can play and one they have to
decode.
Triggers
A trigger has no value, it fires. Read it as an event rather than a state:
let bursts = 0;
function draw() {
if (sialk.parameters.values.burst > bursts) {
bursts = sialk.parameters.values.burst;
// the button was pressed
}
}
Declaring nothing is fine
Plenty of good sketches take no input and just react to the music. The parameter group is simply absent, and the layer still has its own four, scale, position, rotation.