moonbit-motion-lab

    Motion curve toolkit for MoonBit: parameterized curves, cubic Bezier, sampling, diagnostics, and animation value generation

    motion
    animation
    easing
    spring
    bezier
    sampling
    interpolation
    diagnostics
    Download zip
    Version
    0.1.1
    License
    Apache-2.0
    Last updated
    5 hours ago
    Downloads
    2

    #MoonBit Motion Lab

    MoonBit Motion Lab is a motion-curve composition and quality-assurance toolkit for MoonBit. It does not publish a catalogue of named, fixed easing equations or CSS easing presets.

    #Project boundary

    The project starts after a developer has chosen or designed a curve. It provides:

    • parameterized motion primitives (back_in, back_out, spring_out)
    • custom cubic-Bezier evaluation without CSS preset aliases
    • deterministic curve sampling and application-value frame generation
    • numerical curve reports: min/max, maximum speed, peak-speed time, monotonicity, and endpoint error
    • renderer-independent sequential timelines that compile transitions into fixed-rate frames

    Standard named easing collections are intentionally out of scope. This boundary avoids duplicating maintained easing-function packages and makes the project useful for animation tuning, visual regression tests, and data-visualization transitions.

    #Quick start

    let spring = fn(t : Double) -> Double { @motion.spring_out(t, 4.0, 2.0) }
    let report = @motion.profile(spring, 120)
    let timeline = @motion.MotionTimeline::new()
    timeline.append(0.0, 100.0, 0.6, spring)
    timeline.append(100.0, 160.0, 0.4, @motion.linear)
    let frames = timeline.frames(60)

    #Verification

    moon fmt --check moon check moon test moon build moon run ./examples/basic

    #Project identity

    The Mooncakes module and GitHub repository are both Kai-Junhan/moonbit-motion-lab. The local project directory should be renamed from moonbit-easing to moonbit-motion-lab before publishing.

    #License

    Apache-2.0. See LICENSE.

    MotionFn

    type MotionFn = (Double) -> Double

    A normalized motion curve maps progress in [0, 1] to a value.

    CubicBezier

    pub struct CubicBezier {
    x1 : Double
    y1 : Double
    x2 : Double
    y2 : Double
    }

    CubicBezier::new

    fn CubicBezier::new(x1 : Double, y1 : Double, x2 : Double, y2 : Double) -> CubicBezier

    CubicBezier::value_at

    fn CubicBezier::value_at(self : CubicBezier, t : Double) -> Double

    CurveReport

    pub struct CurveReport {
    min_value : Double
    max_value : Double
    max_speed : Double
    time_of_max_speed : Double
    monotonic : Bool
    endpoint_error : Double
    }

    Numerical summary of a normalized motion curve.

    MotionSegment

    pub struct MotionSegment {
    start : Double
    end : Double
    duration : Double
    motion : (Double) -> Double
    }

    One value transition in a sequential motion timeline.

    MotionTimeline

    pub struct MotionTimeline {
    segments : Array[MotionSegment]
    }

    A deterministic, renderer-independent sequence of motion segments.

    MotionTimeline::append

    fn MotionTimeline::append(self : MotionTimeline, start : Double, end : Double, duration : Double, motion : (Double) -> Double) -> Unit

    Add a segment. Non-positive durations are ignored during playback.

    MotionTimeline::duration

    fn MotionTimeline::duration(self : MotionTimeline) -> Double

    Sum the usable durations in this timeline.

    MotionTimeline::frames

    fn MotionTimeline::frames(self : MotionTimeline, fps : Int) -> Array[Double]

    Produce timeline values at a fixed frame rate.

    MotionTimeline::new

    Create an empty motion timeline.

    MotionTimeline::value_at

    fn MotionTimeline::value_at(self : MotionTimeline, time : Double) -> Double

    Evaluate the timeline at elapsed time. An empty timeline evaluates to zero.

    back_in

    fn back_in(t : Double, overshoot : Double) -> Double

    A tunable anticipation curve. overshoot controls how far it pulls back.

    back_out

    fn back_out(t : Double, overshoot : Double) -> Double

    A tunable settling curve. overshoot controls how far it exceeds the end.

    clamp01

    fn clamp01(value : Double) -> Double

    Clamp a value to the normalized animation interval.

    frames

    fn frames(start : Double, end : Double, count : Int, motion : (Double) -> Double) -> Array[Double]

    Generate interpolated application values from a motion curve.

    interpolate

    fn interpolate(start : Double, end : Double, t : Double, motion : (Double) -> Double) -> Double

    Map normalized motion progress onto an application value range.

    is_monotonic

    fn is_monotonic(motion : (Double) -> Double, samples : Int) -> Bool

    Check whether sampled values never decrease.

    linear

    fn linear(t : Double) -> Double

    The identity curve, useful as a baseline in diagnostics and timelines.

    max_overshoot

    fn max_overshoot(motion : (Double) -> Double, samples : Int) -> Double

    Return the largest amount by which a curve exceeds [0, 1].

    profile

    fn profile(motion : (Double) -> Double, samples : Int) -> CurveReport

    Profile a curve using a deterministic number of samples.

    sample

    fn sample(motion : (Double) -> Double, count : Int) -> Array[Double]

    Sample a motion curve at evenly spaced points, including both endpoints.

    spring_out

    fn spring_out(t : Double, frequency : Double, damping : Double) -> Double

    A damped oscillation. frequency and damping are explicit tuning inputs.

    stitch

    fn stitch(first : (Double) -> Double, second : (Double) -> Double, split : Double) -> ((Double) -> Double)

    Join two normalized motions at split.

    velocity

    fn velocity(motion : (Double) -> Double, t : Double, epsilon : Double) -> Double

    Estimate local velocity with a centered finite difference.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io