Motion curve toolkit for MoonBit: parameterized curves, cubic Bezier, sampling, diagnostics, and animation value generation
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)moon fmt --check
moon check
moon test
moon build
moon run ./examples/basictype MotionFn = (Double) -> Doublepub struct CubicBezier {
x1 : Double
y1 : Double
x2 : Double
y2 : Double
}pub struct CurveReport {
min_value : Double
max_value : Double
max_speed : Double
time_of_max_speed : Double
monotonic : Bool
endpoint_error : Double
}pub struct MotionSegment {
start : Double
end : Double
duration : Double
motion : (Double) -> Double
}fn MotionTimeline::append(self : MotionTimeline, start : Double, end : Double, duration : Double, motion : (Double) -> Double) -> Unitfn back_in(t : Double, overshoot : Double) -> Doublefn back_out(t : Double, overshoot : Double) -> Doublefn clamp01(value : Double) -> Doublefn interpolate(start : Double, end : Double, t : Double, motion : (Double) -> Double) -> Doublefn is_monotonic(motion : (Double) -> Double, samples : Int) -> Boolfn linear(t : Double) -> Doublefn max_overshoot(motion : (Double) -> Double, samples : Int) -> Doublefn spring_out(t : Double, frequency : Double, damping : Double) -> Doublefn stitch(first : (Double) -> Double, second : (Double) -> Double, split : Double) -> ((Double) -> Double)fn velocity(motion : (Double) -> Double, t : Double, epsilon : Double) -> DoubleInstall
Download zipMotion curve toolkit for MoonBit: parameterized curves, cubic Bezier, sampling, diagnostics, and animation value generation