harmonica 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +12 -2
- data/harmonica.gemspec +1 -1
- data/lib/harmonica/version.rb +1 -1
- data/sig/harmonica/point.rbs +42 -0
- data/sig/harmonica/projectile.rbs +56 -0
- data/sig/harmonica/spring.rbs +81 -0
- data/sig/harmonica/vector.rbs +71 -0
- data/sig/harmonica/version.rbs +5 -0
- data/sig/harmonica.rbs +13 -0
- metadata +7 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e6afb3b138a76ef0890ade727f4c54101bc82500e7f62414f07cb9354869b81e
|
|
4
|
+
data.tar.gz: '029cf0ad698ed254933e784c38d061aa1888c1605c7d00a19d84071bde203e26'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c03e033b71d53191187bc3384fc9e6f71d6186be710ad3dcbc1090bd251b7ec77663b9a9b0882b4dee15949b3c8747d0bae539481b41788423bb5ad443dd95d9
|
|
7
|
+
data.tar.gz: dbebfb079e65c125ed16ad557db8d550201cecb62db2e29b4f1a54ba0f120980867709c4c9ee3fd5d545b6b4fda8189671fd6814defe4b8f7b8ec29327da6199
|
data/README.md
CHANGED
|
@@ -231,7 +231,7 @@ end
|
|
|
231
231
|
## Development
|
|
232
232
|
|
|
233
233
|
**Requirements:**
|
|
234
|
-
- Ruby 3.
|
|
234
|
+
- Ruby 3.2+
|
|
235
235
|
|
|
236
236
|
**Install dependencies:**
|
|
237
237
|
|
|
@@ -262,4 +262,14 @@ The gem is available as open source under the terms of the MIT License.
|
|
|
262
262
|
|
|
263
263
|
## Acknowledgments
|
|
264
264
|
|
|
265
|
-
This gem is a Ruby implementation of [charmbracelet/harmonica](https://github.com/charmbracelet/harmonica), part of the excellent [Charm](https://charm.sh) ecosystem. The spring algorithm is based on Ryan Juckett's [damped springs](https://www.ryanjuckett.com/damped-springs/).
|
|
265
|
+
This gem is a Ruby implementation of [charmbracelet/harmonica](https://github.com/charmbracelet/harmonica), part of the excellent [Charm](https://charm.sh) ecosystem. The spring algorithm is based on Ryan Juckett's [damped springs](https://www.ryanjuckett.com/damped-springs/). Charm Ruby is not affiliated with or endorsed by Charmbracelet, Inc.
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
Part of [Charm Ruby](https://charm-ruby.dev).
|
|
270
|
+
|
|
271
|
+
<a href="https://charm-ruby.dev"><img alt="Charm Ruby" src="https://marcoroth.dev/images/heros/glamorous-christmas.png" width="400"></a>
|
|
272
|
+
|
|
273
|
+
[Lipgloss](https://github.com/marcoroth/lipgloss-ruby) • [Bubble Tea](https://github.com/marcoroth/bubbletea-ruby) • [Bubbles](https://github.com/marcoroth/bubbles-ruby) • [Glamour](https://github.com/marcoroth/glamour-ruby) • [Huh?](https://github.com/marcoroth/huh-ruby) • [Harmonica](https://github.com/marcoroth/harmonica-ruby) • [Bubblezone](https://github.com/marcoroth/bubblezone-ruby) • [Gum](https://github.com/marcoroth/gum-ruby) • [ntcharts](https://github.com/marcoroth/ntcharts-ruby)
|
|
274
|
+
|
|
275
|
+
The terminal doesn't have to be boring.
|
data/harmonica.gemspec
CHANGED
data/lib/harmonica/version.rb
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Generated from lib/harmonica/point.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Harmonica
|
|
4
|
+
# Point represents a point in 3D space.
|
|
5
|
+
#
|
|
6
|
+
# @example
|
|
7
|
+
# point = Harmonica::Point.new(10.0, 20.0, 0.0)
|
|
8
|
+
# point.x # => 10.0
|
|
9
|
+
# point.y # => 20.0
|
|
10
|
+
# point.z # => 0.0
|
|
11
|
+
class Point
|
|
12
|
+
@x: Float
|
|
13
|
+
|
|
14
|
+
@y: Float
|
|
15
|
+
|
|
16
|
+
@z: Float
|
|
17
|
+
|
|
18
|
+
attr_accessor x: Float
|
|
19
|
+
|
|
20
|
+
attr_accessor y: Float
|
|
21
|
+
|
|
22
|
+
attr_accessor z: Float
|
|
23
|
+
|
|
24
|
+
# @rbs x: Integer | Float -- x coordinate
|
|
25
|
+
# @rbs y: Integer | Float -- y coordinate
|
|
26
|
+
# @rbs z: Integer | Float -- z coordinate
|
|
27
|
+
# @rbs return: void
|
|
28
|
+
def initialize: (?Integer | Float x, ?Integer | Float y, ?Integer | Float z) -> void
|
|
29
|
+
|
|
30
|
+
# : () -> Array[Float]
|
|
31
|
+
def to_a: () -> Array[Float]
|
|
32
|
+
|
|
33
|
+
# : (untyped other) -> bool
|
|
34
|
+
def ==: (untyped other) -> bool
|
|
35
|
+
|
|
36
|
+
# : () -> String
|
|
37
|
+
def to_s: () -> String
|
|
38
|
+
|
|
39
|
+
# : () -> String
|
|
40
|
+
def inspect: () -> String
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Generated from lib/harmonica/projectile.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Harmonica
|
|
4
|
+
# Projectile simulates physics projectile motion.
|
|
5
|
+
#
|
|
6
|
+
# @example
|
|
7
|
+
# projectile = Harmonica::Projectile.new(
|
|
8
|
+
# delta_time: Harmonica.fps(60),
|
|
9
|
+
# position: Harmonica::Point.new(0, 100, 0),
|
|
10
|
+
# velocity: Harmonica::Vector.new(2, 0, 0),
|
|
11
|
+
# acceleration: Harmonica::GRAVITY
|
|
12
|
+
# )
|
|
13
|
+
#
|
|
14
|
+
# loop do
|
|
15
|
+
# position = projectile.update
|
|
16
|
+
# break if position.y <= 0
|
|
17
|
+
# end
|
|
18
|
+
class Projectile
|
|
19
|
+
@delta_time: Float
|
|
20
|
+
|
|
21
|
+
@position: Point
|
|
22
|
+
|
|
23
|
+
@velocity: Vector
|
|
24
|
+
|
|
25
|
+
@acceleration: Vector
|
|
26
|
+
|
|
27
|
+
attr_reader position: Point
|
|
28
|
+
|
|
29
|
+
attr_reader velocity: Vector
|
|
30
|
+
|
|
31
|
+
attr_reader acceleration: Vector
|
|
32
|
+
|
|
33
|
+
attr_reader delta_time: Float
|
|
34
|
+
|
|
35
|
+
# Create a new Projectile.
|
|
36
|
+
#
|
|
37
|
+
# @rbs delta_time: Float -- time step per frame (use Harmonica.fps)
|
|
38
|
+
# @rbs position: Point -- initial position
|
|
39
|
+
# @rbs velocity: Vector -- initial velocity
|
|
40
|
+
# @rbs acceleration: Vector -- constant acceleration (e.g., gravity)
|
|
41
|
+
# @rbs return: void
|
|
42
|
+
def initialize: (delta_time: Float, position: Point, velocity: Vector, acceleration: Vector) -> void
|
|
43
|
+
|
|
44
|
+
# Update the projectile position and velocity for one time step.
|
|
45
|
+
#
|
|
46
|
+
# : () -> Point
|
|
47
|
+
def update: () -> Point
|
|
48
|
+
|
|
49
|
+
# Reset the projectile to a new state.
|
|
50
|
+
#
|
|
51
|
+
# @rbs position: Point -- new position
|
|
52
|
+
# @rbs velocity: Vector -- new velocity
|
|
53
|
+
# @rbs return: void
|
|
54
|
+
def reset: (position: Point, velocity: Vector) -> void
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Generated from lib/harmonica/spring.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Harmonica
|
|
4
|
+
# Spring is a damped harmonic oscillator for smooth, realistic spring-like motion.
|
|
5
|
+
#
|
|
6
|
+
# This is ported from Ryan Juckett's simple damped harmonic motion, originally
|
|
7
|
+
# written in C++. For background on the algorithm see:
|
|
8
|
+
# https://www.ryanjuckett.com/damped-springs/
|
|
9
|
+
#
|
|
10
|
+
# @example
|
|
11
|
+
# # Initialize once
|
|
12
|
+
# spring = Harmonica::Spring.new(
|
|
13
|
+
# delta_time: Harmonica.fps(60),
|
|
14
|
+
# angular_frequency: 6.0,
|
|
15
|
+
# damping_ratio: 0.2
|
|
16
|
+
# )
|
|
17
|
+
#
|
|
18
|
+
# # Update on every frame
|
|
19
|
+
# position = 0.0
|
|
20
|
+
# velocity = 0.0
|
|
21
|
+
# target = 100.0
|
|
22
|
+
#
|
|
23
|
+
# loop do
|
|
24
|
+
# position, velocity = spring.update(position, velocity, target)
|
|
25
|
+
# end
|
|
26
|
+
class Spring
|
|
27
|
+
EPSILON: Float
|
|
28
|
+
|
|
29
|
+
@velocity_velocity_coefficient: Float
|
|
30
|
+
|
|
31
|
+
@velocity_position_coefficient: Float
|
|
32
|
+
|
|
33
|
+
@position_velocity_coefficient: Float
|
|
34
|
+
|
|
35
|
+
@position_position_coefficient: Float
|
|
36
|
+
|
|
37
|
+
@angular_frequency: Float
|
|
38
|
+
|
|
39
|
+
@damping_ratio: Float
|
|
40
|
+
|
|
41
|
+
@delta_time: Float
|
|
42
|
+
|
|
43
|
+
attr_reader position_position_coefficient: Float
|
|
44
|
+
|
|
45
|
+
attr_reader position_velocity_coefficient: Float
|
|
46
|
+
|
|
47
|
+
attr_reader velocity_position_coefficient: Float
|
|
48
|
+
|
|
49
|
+
attr_reader velocity_velocity_coefficient: Float
|
|
50
|
+
|
|
51
|
+
# Create a new Spring with precomputed coefficients.
|
|
52
|
+
#
|
|
53
|
+
# @rbs delta_time: Float -- time step (use Harmonica.fps for frame rate)
|
|
54
|
+
# @rbs angular_frequency: Float -- angular frequency of motion (affects speed)
|
|
55
|
+
# @rbs damping_ratio: Float -- damping ratio (> 1: over-damped, = 1: critical, < 1: under-damped)
|
|
56
|
+
# @rbs return: void
|
|
57
|
+
def initialize: (delta_time: Float, angular_frequency: Float, damping_ratio: Float) -> void
|
|
58
|
+
|
|
59
|
+
# Update position and velocity towards equilibrium position.
|
|
60
|
+
#
|
|
61
|
+
# @rbs position: Float -- current position
|
|
62
|
+
# @rbs velocity: Float -- current velocity
|
|
63
|
+
# @rbs equilibrium_position: Float -- target/equilibrium position
|
|
64
|
+
# @rbs return: [Float, Float]
|
|
65
|
+
def update: (Float position, Float velocity, Float equilibrium_position) -> [ Float, Float ]
|
|
66
|
+
|
|
67
|
+
private
|
|
68
|
+
|
|
69
|
+
# : () -> void
|
|
70
|
+
def compute_coefficients: () -> void
|
|
71
|
+
|
|
72
|
+
# : () -> void
|
|
73
|
+
def compute_over_damped: () -> void
|
|
74
|
+
|
|
75
|
+
# : () -> void
|
|
76
|
+
def compute_under_damped: () -> void
|
|
77
|
+
|
|
78
|
+
# : () -> void
|
|
79
|
+
def compute_critically_damped: () -> void
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Generated from lib/harmonica/vector.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Harmonica
|
|
4
|
+
# Vector represents a vector in 3D space with magnitude and direction.
|
|
5
|
+
#
|
|
6
|
+
# @example
|
|
7
|
+
# velocity = Harmonica::Vector.new(2.0, 0.0, 0.0)
|
|
8
|
+
# gravity = Harmonica::GRAVITY
|
|
9
|
+
class Vector
|
|
10
|
+
@x: Float
|
|
11
|
+
|
|
12
|
+
@y: Float
|
|
13
|
+
|
|
14
|
+
@z: Float
|
|
15
|
+
|
|
16
|
+
attr_accessor x: Float
|
|
17
|
+
|
|
18
|
+
attr_accessor y: Float
|
|
19
|
+
|
|
20
|
+
attr_accessor z: Float
|
|
21
|
+
|
|
22
|
+
# @rbs x: Integer | Float -- x component
|
|
23
|
+
# @rbs y: Integer | Float -- y component
|
|
24
|
+
# @rbs z: Integer | Float -- z component
|
|
25
|
+
# @rbs return: void
|
|
26
|
+
def initialize: (?Integer | Float x, ?Integer | Float y, ?Integer | Float z) -> void
|
|
27
|
+
|
|
28
|
+
# : () -> Array[Float]
|
|
29
|
+
def to_a: () -> Array[Float]
|
|
30
|
+
|
|
31
|
+
# : (untyped other) -> bool
|
|
32
|
+
def ==: (untyped other) -> bool
|
|
33
|
+
|
|
34
|
+
# : () -> String
|
|
35
|
+
def to_s: () -> String
|
|
36
|
+
|
|
37
|
+
# : () -> String
|
|
38
|
+
def inspect: () -> String
|
|
39
|
+
|
|
40
|
+
# Vector addition
|
|
41
|
+
#
|
|
42
|
+
# : (Vector other) -> Vector
|
|
43
|
+
def +: (Vector other) -> Vector
|
|
44
|
+
|
|
45
|
+
# Vector subtraction
|
|
46
|
+
#
|
|
47
|
+
# : (Vector other) -> Vector
|
|
48
|
+
def -: (Vector other) -> Vector
|
|
49
|
+
|
|
50
|
+
# Scalar multiplication
|
|
51
|
+
#
|
|
52
|
+
# : (Integer | Float other) -> Vector
|
|
53
|
+
def *: (Integer | Float other) -> Vector
|
|
54
|
+
|
|
55
|
+
# Magnitude (length) of the vector
|
|
56
|
+
#
|
|
57
|
+
# : () -> Float
|
|
58
|
+
def magnitude: () -> Float
|
|
59
|
+
|
|
60
|
+
# Normalize the vector (unit vector)
|
|
61
|
+
#
|
|
62
|
+
# : () -> Vector
|
|
63
|
+
def normalize: () -> Vector
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# origin at bottom-left, Y pointing up
|
|
67
|
+
GRAVITY: Vector
|
|
68
|
+
|
|
69
|
+
# origin at top-left, Y pointing down
|
|
70
|
+
TERMINAL_GRAVITY: Vector
|
|
71
|
+
end
|
data/sig/harmonica.rbs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Generated from lib/harmonica.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Harmonica
|
|
4
|
+
# Calculate time delta for a given frames per second.
|
|
5
|
+
# Use this when initializing Spring or Projectile.
|
|
6
|
+
#
|
|
7
|
+
# @example
|
|
8
|
+
# spring = Harmonica::Spring.new(delta_time: Harmonica.fps(60), ...)
|
|
9
|
+
#
|
|
10
|
+
# @rbs frames_per_second: Integer -- frames per second
|
|
11
|
+
# @rbs return: Float
|
|
12
|
+
def self.fps: (Integer frames_per_second) -> Float
|
|
13
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: harmonica
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Marco Roth
|
|
@@ -26,6 +26,12 @@ files:
|
|
|
26
26
|
- lib/harmonica/spring.rb
|
|
27
27
|
- lib/harmonica/vector.rb
|
|
28
28
|
- lib/harmonica/version.rb
|
|
29
|
+
- sig/harmonica.rbs
|
|
30
|
+
- sig/harmonica/point.rbs
|
|
31
|
+
- sig/harmonica/projectile.rbs
|
|
32
|
+
- sig/harmonica/spring.rbs
|
|
33
|
+
- sig/harmonica/vector.rbs
|
|
34
|
+
- sig/harmonica/version.rbs
|
|
29
35
|
homepage: https://github.com/marcoroth/harmonica-ruby
|
|
30
36
|
licenses:
|
|
31
37
|
- MIT
|