Motion
Spring and tween animations (spring, tween) stepped once per frame, plus perceptual Color utilities.
local width = Flux.spring(function() return if open() then 300 else 0 end)Types
Spring type
type Spring<T> = setmetatable<
{
read peek: (self: any) -> T,
read get: (self: any) -> T,
read set: (self: any, value: T | Graph.Node<T>, force: boolean?) -> T,
read update: <N>(self: N, fn: ((current: T) -> T | Graph.Node<T>)?) -> N,
read Destroy: (self: any) -> (),
read onDestroy: (self: any, fn: (oldValue: T) -> ()) -> (),
-- Adds `delta` to the spring's current velocity without changing its target.
read impulse: (self: any, delta: T | Graph.Node<T>) -> (),
-- Replaces the spring's velocity outright without changing its target.
read setVelocity: (self: any, velocity: T | Graph.Node<T>) -> (),
-- Sets the spring's current animated value immediately without altering its target or velocity.
read setCurrent: (self: any, value: T | Graph.Node<T>) -> (),
-- Jumps both the target and current value to `value` (or the current target when omitted) and zeroes velocity.
read snap: <N>(self: N, value: (T | Graph.Node<T>)?) -> N,
},
Graph.Operators<T>
>Tween type
type Tween<T> = setmetatable<
{
read peek: (self: any) -> T,
read get: (self: any) -> T,
read set: (self: any, value: T | Graph.Node<T>, force: boolean?) -> T,
read update: <N>(self: N, fn: ((current: T) -> T | Graph.Node<T>)?) -> N,
read Destroy: (self: any) -> (),
read onDestroy: (self: any, fn: (oldValue: T) -> ()) -> (),
-- Jumps both the target and current value to `value` (or the current target when omitted) and stops the tween.
read snap: <N>(self: N, value: (T | Graph.Node<T>)?) -> N,
},
Graph.Operators<T>
>TweenConfig type
type TweenConfig = {
Time: number?,
EasingStyle: (Enum.EasingStyle | string)?,
EasingDirection: (Enum.EasingDirection | string)?,
RepeatCount: number?,
Reverses: boolean?,
DelayTime: number?,
}Functions
step
Motion.step(dt: number?)Advances every active spring and tween by dt seconds (or the time since the last step). Wired to RunService automatically in Roblox, so you only call this in tests (Flux.Motion.step(1 / 60)).
spring
Motion.spring<A>(target: A, frequency: Reactive<number>?, damping: Reactive<number>?, initialVelocity: any?): Spring<Unwrap<A>>Creates a node that animates toward target using an analytic harmonic oscillator (frequency in Hz and damping ratio both default to 1 and may be reactive). Retargets preserve current velocity.
local size = Flux.spring(function() return if open() then 300 else 0 end, 4)tween
Motion.tween<A>(target: A, tweenInfo: Reactive<TweenInfo | TweenConfig>?): Tween<Unwrap<A>>Creates a node that eases toward target over a TweenInfo curve. When starting from rest or between repeats, DelayTime is honored; retargeting an active tween restarts immediately without waiting for DelayTime.
Oklab
fromLinear
Converts a Color3 in linear sRGB space to a Vector3 in Oklab space.
toLinear
Converts a Vector3 in Oklab space to a Color3 in linear sRGB space.
fromRGB
Converts a Color3 in sRGB space to a Vector3 in Oklab space.
toRGB
Converts a Vector3 in Oklab space to a Color3 in sRGB space.
lighten
Raises Oklab lightness by amount (negative darkens).
saturate
Raises Oklab chroma by amount, preserving hue and lightness (negative desaturates).
rotateHue
Rotates hue by degrees, preserving chroma and lightness.
grayscale
Removes all chroma, preserving Oklab lightness.
mix
Linearly interpolates between lab1 and lab2 in Oklab space by alpha.
sRGB
fromLinear
Converts linear sRGB space to sRGB space.
toLinear
Converts sRGB space to linear sRGB space.
Color
lighten
Raises the perceptual lightness of c in Oklab space by amount (negative darkens).
saturate
Raises the chroma of c in Oklab space by amount while preserving hue and lightness (negative desaturates).
rotateHue
Rotates the hue of c by degrees around the Oklab color wheel while preserving chroma and lightness.
grayscale
Strips all chroma from c, returning a neutral gray with the same Oklab perceptual lightness.
mix
Blends a and b in Oklab space by unclamped fraction t (0 = a, 1 = b).
luminance
Motion.Color.luminance(c: Color3): numberReturns the WCAG relative luminance of c from 0 (black) to 1 (white).
contrast
Returns the WCAG contrast ratio between a and b from 1 (identical) to 21 (black on white).
readable
Returns whichever of dark (default black) or light (default white) has the higher WCAG contrast ratio against bg.
Spring
Constructors: Motion.spring · Motion.tween
set
Spring:set(value: any, _force: boolean?): anyRetargets the animation toward value from its current position (motion(value) does the same). If value is a node, it's read once.
update
Spring:update<N>(fn: ((current: any) -> any)?): NRetargets the animation relative to its current target (not its current mid-flight value), calling fn(target) untracked.
impulse
Spring:impulse<T>(delta: T)(Spring only) Adds delta to the spring's current velocity without changing its goal.
setVelocity
Spring:setVelocity<T>(velocity: T)(Spring only) Replaces the spring's current velocity with velocity without changing its goal.
setCurrent
Spring:setCurrent<T>(value: T)(Spring only) Sets the spring's current animated value immediately without changing its target or velocity.
snap
Spring:snap<T>(value: T?): anyJumps both the target and current value to value (or the current target when value is omitted), stopping active motion and resetting velocity/repeat state.