package miaou-core

  1. Overview
  2. Docs
Miaou core/widgets (no drivers, no SDL)

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.5.2.tar.gz
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

Sourcetype easing =
  1. | Linear
    (*

    Constant speed.

    *)
  2. | Ease_in
    (*

    Slow start, accelerating (cubic).

    *)
  3. | Ease_out
    (*

    Fast start, decelerating (cubic).

    *)
  4. | Ease_in_out
    (*

    Slow start and end (cubic).

    *)
  5. | Bounce
    (*

    Overshoots to ~1.1 then settles back to 1.0. Useful for "pop" / impact effects in games.

    *)
  6. | 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.

Sourcetype repeat =
  1. | Once
    (*

    Stops at 1.0 and finished returns true.

    *)
  2. | Loop
    (*

    Wraps back to 0.0 and repeats indefinitely.

    *)
  3. | Ping_pong
    (*

    Reverses direction at each end, oscillating 0→1→0 indefinitely.

    *)

What happens when the animation reaches the end of its duration.

Animation value

Sourcetype t

An opaque animation state.

Creation

Sourceval create : duration:float -> ?easing:easing -> ?repeat:repeat -> unit -> t

Create a new animation.

  • parameter duration

    Total duration in seconds (must be > 0).

  • parameter easing

    Easing curve (default: Linear).

  • parameter repeat

    Repeat mode (default: Once).

Updating

Sourceval tick : t -> dt:float -> t

Advance the animation by dt seconds.

For Once animations, progress is clamped to 1.0. For Loop, it wraps around. For Ping_pong, it reverses.

Sourceval reset : t -> t

Reset the animation to the beginning (elapsed = 0).

Reading

Sourceval value : t -> float

The current eased progress, in the range [0.0, 1.0].

Sourceval raw : t -> float

The raw (linear) progress before easing, in [0.0, 1.0].

Sourceval finished : t -> bool

true when a Once animation has reached its full duration. Always false for Loop and Ping_pong.

Sourceval elapsed : t -> float

Total elapsed time in seconds (may exceed duration for Once).

Interpolation helpers

Sourceval lerp : float -> float -> t -> float

lerp a b anim linearly interpolates between a and b using the eased value. Returns a when value is 0, b when 1.

Sourceval lerp_int : int -> int -> t -> int

Integer version of lerp (result is rounded to nearest int).

Combinators

Sourceval delay : float -> t

delay seconds creates an animation that stays at value 0.0 for seconds, then finishes. Useful for inserting pauses into a sequence.

  • parameter seconds

    Delay duration (clamped to > 0).

Sourceval sequence : t list -> t

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.