Interpolation functions for smooth transitions between values.
Provides various interpolation methods for numbers, colors, strings, arrays, and other data types.
Examples
# Number interpolation
interp = Visualize.Interpolate.number(0, 100)
interp.(0.5) # => 50.0
# Color interpolation (RGB)
interp = Visualize.Interpolate.rgb("#ff0000", "#0000ff")
interp.(0.5) # => "#800080" (purple)
# String interpolation with embedded numbers
interp = Visualize.Interpolate.string("10px solid red", "20px solid blue")
interp.(0.5) # => "15px solid ..."
Summary
Functions
Creates an interpolator between two lists of numbers.
Creates a basis spline interpolator through a series of values.
Creates an interpolator between two Date values.
Creates an interpolator between two DateTime values.
Creates a discrete interpolator that returns one of n values.
Creates an HSL color interpolator.
Creates an HSL interpolator that takes the long path around the hue circle.
Creates a linear interpolator between two numbers.
Creates an RGB color interpolator.
Interpolates between two numbers, rounding to the nearest integer.
Creates an interpolator for strings containing numbers.
Creates an interpolator for SVG transform strings.
Creates a smooth zoom interpolator between two views.
Functions
Creates an interpolator between two lists of numbers.
Lists must be the same length.
Examples
interp = Visualize.Interpolate.array([0, 0], [100, 200])
interp.(0.5) # => [50.0, 100.0]
Creates a basis spline interpolator through a series of values.
Returns smooth values that pass near (but not through) control points.
Examples
interp = Visualize.Interpolate.basis([0, 10, 5, 20, 15])
interp.(0.5) # Smooth value around middle
Creates an interpolator between two Date values.
@spec datetime(DateTime.t(), DateTime.t()) :: (number() -> DateTime.t())
Creates an interpolator between two DateTime values.
Examples
start = ~U[2024-01-01 00:00:00Z]
finish = ~U[2024-12-31 00:00:00Z]
interp = Visualize.Interpolate.datetime(start, finish)
interp.(0.5) # => ~U[2024-07-01 ...]
Creates a discrete interpolator that returns one of n values.
Useful for stepped animations or categorical transitions.
Examples
interp = Visualize.Interpolate.discrete(["a", "b", "c", "d"])
interp.(0.0) # => "a"
interp.(0.25) # => "b"
interp.(0.99) # => "d"
Creates an HSL color interpolator.
Interpolating in HSL space often produces more pleasing transitions than RGB, especially for colors that are far apart on the color wheel.
Examples
interp = Visualize.Interpolate.hsl("#ff0000", "#00ff00")
interp.(0.5) # Interpolates through yellow
Creates an HSL interpolator that takes the long path around the hue circle.
Creates a linear interpolator between two numbers.
Examples
interp = Visualize.Interpolate.number(0, 100)
interp.(0.0) # => 0.0
interp.(0.5) # => 50.0
interp.(1.0) # => 100.0
Creates an RGB color interpolator.
Accepts hex strings, RGB tuples, or Color structs.
Examples
interp = Visualize.Interpolate.rgb("#ff0000", "#0000ff")
interp.(0.5) # => "#800080"
Interpolates between two numbers, rounding to the nearest integer.
Creates an interpolator for strings containing numbers.
Numbers in the string are interpolated while other characters are preserved from the ending string.
Examples
interp = Visualize.Interpolate.string("10px", "20px")
interp.(0.5) # => "15px"
interp = Visualize.Interpolate.string("rotate(0)", "rotate(180)")
interp.(0.5) # => "rotate(90)"
Creates an interpolator for SVG transform strings.
Handles translate, scale, and rotate transformations.
Examples
interp = Visualize.Interpolate.transform(
"translate(0, 0) rotate(0)",
"translate(100, 50) rotate(90)"
)
interp.(0.5) # => "translate(50, 25) rotate(45)"
Creates a smooth zoom interpolator between two views.
Views are specified as [cx, cy, width] representing the center point and visible width. Uses van Wijk and Nuij's algorithm.
Examples
interp = Visualize.Interpolate.zoom(
[0, 0, 100], # Start: centered at origin, width 100
[500, 300, 50] # End: centered at (500,300), width 50
)
[cx, cy, w] = interp.(0.5)