1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Allow these clippy lints for physics/math code readability
//! # Harmonica
//!
//! Physics-based animation tools for 2D and 3D applications.
//!
//! Harmonica provides:
//! - **Spring**: A damped harmonic oscillator for smooth, realistic motion
//! - **Projectile**: A simple projectile simulator for particles and projectiles
//!
//! ## Role in `charmed_rust`
//!
//! Harmonica is a foundational crate that supplies physics-based motion used across
//! the ecosystem:
//! - **bubbletea** uses it for time-based animation helpers.
//! - **bubbles** uses it to animate components like progress bars.
//! - **demo_showcase** uses it to demonstrate smooth, springy UI motion.
//!
//! ## Spring Example
//!
//! ```rust
//! use harmonica::{fps, Spring};
//!
//! // Initialize the spring once
//! let spring = Spring::new(fps(60), 6.0, 0.2);
//!
//! // Update in your animation loop
//! let mut pos = 0.0;
//! let mut vel = 0.0;
//! let target = 100.0;
//!
//! // Simulate for 2 seconds (120 frames at 60 FPS)
//! for _ in 0..120 {
//! (pos, vel) = spring.update(pos, vel, target);
//! }
//!
//! // Position should approach target
//! assert!((pos - target).abs() < 5.0);
//! ```
//!
//! ## Projectile Example
//!
//! ```rust
//! use harmonica::{fps, Point, Vector, Projectile, TERMINAL_GRAVITY};
//!
//! // Create a projectile with gravity
//! let mut projectile = Projectile::new(
//! fps(60),
//! Point::new(0.0, 0.0, 0.0),
//! Vector::new(10.0, -5.0, 0.0),
//! TERMINAL_GRAVITY,
//! );
//!
//! // Update each frame
//! let pos = projectile.update();
//! ```
//!
//! ## Damping Ratios
//!
//! The damping ratio determines the spring's behavior:
//!
//! - **Over-damped (ζ > 1)**: No oscillation, slow return to equilibrium
//! - **Critically-damped (ζ = 1)**: Fastest return without oscillation
//! - **Under-damped (ζ < 1)**: Oscillates around equilibrium with decay
//!
//! ## Attribution
//!
//! The spring algorithm is based on Ryan Juckett's damped harmonic motion:
//! <https://www.ryanjuckett.com/damped-springs/>
pub use ;
pub use ;
/// Prelude module for convenient imports.