package miaou-core
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=60a3b9f181f24572a06a9492532bfdda
sha512=fcc35a275066be2900e6201782faf47503076fa4640f08cf78067835a6f447b74613009e55b2ac799adb7ca46f1bffa261fc5971753f2cc3c6bef327511c7ef6
doc/miaou-core.helpers/Miaou_helpers/Animation/index.html
Module Miaou_helpers.AnimationSource
Time-based animation primitives.
This module provides a single t value that tracks progress through an animation defined by a duration and an easing curve. The caller is responsible for feeding delta-time via tick; the module has no dependency on the framework clock.
Typical usage with the Clock capability:
(* Create a 300 ms ease-out transition *)
let anim = Animation.create ~duration:0.3 ~easing:Ease_out ()
(* Each frame, advance by the clock delta *)
let anim = Animation.tick anim ~dt:(clock.dt ())
(* Read the eased progress (0.0 .. 1.0) *)
let progress = Animation.lerp 30.0 80.0 anim (* 30 → 80 *)Repeating animations:
(* Continuous loop (e.g. spinner) *)
let spin = Animation.create ~duration:1.0 ~repeat:Loop ()
(* Ping-pong pulse (e.g. focus glow) *)
let pulse = Animation.create ~duration:0.8
~repeat:Ping_pong ~easing:Ease_in_out ()Configuration
type easing = | Linear(*Constant speed.
*)| Ease_in(*Slow start, accelerating (cubic).
*)| Ease_out(*Fast start, decelerating (cubic).
*)| Ease_in_out(*Slow start and end (cubic).
*)| Bounce(*Overshoots to ~1.1 then settles back to 1.0. Useful for "pop" / impact effects in games.
*)| Custom of float -> float(*User-supplied easing function. Receives raw progress in
*)[0, 1], should return the eased value (may exceed[0, 1]for overshoot effects).
Easing curve applied to the raw linear progress.
What happens when the animation reaches the end of its duration.
Animation value
An opaque animation state.
Creation
Create a new animation.
Updating
Reading
Interpolation helpers
lerp a b anim linearly interpolates between a and b using the eased value. Returns a when value is 0, b when 1.
Integer version of lerp (result is rounded to nearest int).
Combinators
delay seconds creates an animation that stays at value 0.0 for seconds, then finishes. Useful for inserting pauses into a sequence.
sequence anims chains a list of animations end-to-end. The resulting animation's value is that of whichever sub-animation is currently active. finished is true only when the last sub-animation finishes.
An empty list produces an already-finished animation with value 0.
Example — flash, hold, then fade out:
Animation.sequence [
Animation.create ~duration:0.1 ~easing:Ease_out () ; (* flash in *)
Animation.delay 0.5 ; (* hold *)
Animation.create ~duration:0.3 ~easing:Ease_in () ; (* fade out *)
]Note: sub-animations should use Once repeat mode. Loop and Ping_pong sub-animations never finish, so subsequent steps would never be reached.