Skip to content

Sliders and animation

A definition given a slider range becomes a slider. Mark it playing and the graph animates as soon as it opens.

examples/06-sliders-and-animation.axis

config {
showGrid: true
}
"Sliders"
// A range is written low..high, with an optional step after it.
a = 1 @ slider: -5..5 step 0.5
b = 0 @ slider: -3..3 step 0.1
c = 1 @ slider: 0.5..4 step 0.25
"Drag a, b and c to reshape the parabola."
y = a * (x - b) ^ 2 + c @ color: RED, lineWidth: 3
// The vertex, tracked as the sliders move.
(b, c) @ color: RED, pointSize: 15, label: "vertex", showLabel, labelOrientation: above
folder "Ranges" {
"An end left off keeps Desmos' own default for it - here the top, 10."
p = 2 @ slider: 0.. step 1
"Both ends stop the slider by default. soft lets a value typed in go past them; soft min or soft max softens just the one."
q = 1 @ slider: -2..2 soft
k = 1 @ slider: 0..3 step 0.5 soft max
"Any end, and the step, may be an expression - so one slider can set the reach of another."
lim = 3 @ slider: 1..6 step 1
s = 1 @ slider: -lim..lim step lim / 10
y = p + q * sin(k * x) + s @ color: GREEN, lineOpacity: 0.6
}
folder "Animation" {
"playing starts the slider moving on load."
t = 0 @ slider: 0..2pi step 0.02, playing
"A point riding the wave."
(t, sin(t)) @ color: BLUE, pointSize: 18
y = sin(x) @ color: BLUE, lineOpacity: 0.4
"A trailing chord back to the origin."
Q = [(0, 0), (t, sin(t))] @ color: ORANGE, lines, points: false, lineStyle: DASHED
}
Open in playground →