All Projects → charmbracelet → harmonica

charmbracelet / harmonica

Licence: MIT license
A simple, physics-based animation library 🎼

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to harmonica

arpes
Mirror of PyARPES (gitlab/lanzara-group/python-arpes) the open source ARPES analysis framework
Stars: ✭ 21 (-96.32%)
Mutual labels:  physics
plottr
A flexible plotting and data analysis tool.
Stars: ✭ 32 (-94.4%)
Mutual labels:  physics
fdtd3d
fdtd3d is an open source 1D, 2D, 3D FDTD electromagnetics solver with MPI, OpenMP and CUDA support for x86, arm, arm64 architectures
Stars: ✭ 77 (-86.51%)
Mutual labels:  physics
billiards
billiards physics
Stars: ✭ 37 (-93.52%)
Mutual labels:  physics
moac
Generate passwords and analyze their strength given physical limits to computation
Stars: ✭ 16 (-97.2%)
Mutual labels:  physics
GDCustomRaycastVehicle
A simple custom raycast vehicle implementation
Stars: ✭ 36 (-93.7%)
Mutual labels:  physics
Py3ODE
Port of PyODE for Python 3
Stars: ✭ 29 (-94.92%)
Mutual labels:  physics
03-Unstable-Rotation
The code for my Game Physics course: https://www.udemy.com/gamephysics
Stars: ✭ 21 (-96.32%)
Mutual labels:  physics
tikz
Random collection of standalone TikZ images
Stars: ✭ 87 (-84.76%)
Mutual labels:  physics
SymbolicTensors.jl
Manipulate tensors symbolically in Julia! Currently needs a SymPy dependency, but work is ongoing to change the backend to SymbolicUtils.jl
Stars: ✭ 26 (-95.45%)
Mutual labels:  physics
image-to-box2d-body
proof-of-concept game build pipeline for converting an image to a Box2D body
Stars: ✭ 24 (-95.8%)
Mutual labels:  physics
creative-coding-notebooks
🎨 An authorial collection of fundamental recipes on Creative Coding and Recreational Programming.
Stars: ✭ 17 (-97.02%)
Mutual labels:  physics
Legion-Engine
Rythe is a data-oriented C++17 game engine built to make optimal use of modern hardware.
Stars: ✭ 502 (-12.08%)
Mutual labels:  physics
ux-animate
A simple but powerful tweening, spring physics, animation library for Rust
Stars: ✭ 19 (-96.67%)
Mutual labels:  physics
NMRI
2D Fourier Transform of Nuclear Magnetic Resonance Imaging raw data
Stars: ✭ 13 (-97.72%)
Mutual labels:  physics
workshop
Workshop: Micromagnetics with Ubermag
Stars: ✭ 19 (-96.67%)
Mutual labels:  physics
cas
Cellular Automata Simulator
Stars: ✭ 22 (-96.15%)
Mutual labels:  physics
MachineLearning Physics
This is to facilitate the “Machine Learning in Physics” course that I am teaching at Sharif University of Technology for winter-19 semester. For more information, see the course page at
Stars: ✭ 26 (-95.45%)
Mutual labels:  physics
diepssect
A public repo for hacky diep stuff - networking protocol, WebAssembly, memory editing, & physics
Stars: ✭ 26 (-95.45%)
Mutual labels:  physics
Libbulletjme
A JNI interface to Bullet Physics and V-HACD
Stars: ✭ 55 (-90.37%)
Mutual labels:  physics

Harmonica

Harmonica Image
Latest Release GoDoc Build Status

A simple, efficient spring animation library for smooth, natural motion.

Harmonica OpenGL Demo

It even works well on the command line.

Harmonica TUI Demo

Usage

Harmonica is framework-agnostic and works well in 2D and 3D contexts. Simply call NewSpring with your settings to initialize and Update on each frame to animate.

import "github.com/charmbracelet/harmonica"

// A thing we want to animate.
sprite := struct{
    x, xVelocity float64
    y, yVelocity float64
}{}

// Where we want to animate it.
const targetX = 50.0
const targetY = 100.0

// Initialize a spring with framerate, angular frequency, and damping values.
spring := harmonica.NewSpring(harmonica.FPS(60), 6.0, 0.5)

// Animate!
for {
    sprite.x, sprite.xVelocity = spring.Update(sprite.x, sprite.xVelocity, targetX)
    sprite.y, sprite.yVelocity = spring.Update(sprite.y, sprite.yVelocity, targetY)
    time.Sleep(time.Second/60)
}

For details, see the examples and the docs.

Settings

NewSpring takes three values:

  • Time Delta: the time step to operate on. Game engines typically provide a way to determine the time delta, however if that's not available you can simply set the framerate with the included FPS(int) utility function. Make the framerate you set here matches your actual framerate.
  • Angular Velocity: this translates roughly to the speed. Higher values are faster.
  • Damping Ratio: the springiness of the animation, generally between 0 and 1, though it can go higher. Lower values are springier. For details, see below.

Damping Ratios

The damping ratio affects the motion in one of three different ways depending on how it's set.

Under-Damping

A spring is under-damped when its damping ratio is less than 1. An under-damped spring reaches equilibrium the fastest, but overshoots and will continue to oscillate as its amplitude decays over time.

Critical Damping

A spring is critically-damped the damping ratio is exactly 1. A critically damped spring will reach equilibrium as fast as possible without oscillating.

Over-Damping

A spring is over-damped the damping ratio is greater than 1. An over-damped spring will never oscillate, but reaches equilibrium at a slower rate than a critically damped spring.

Acknowledgements

This library is a fairly straightforward port of Ryan Juckett’s excellent damped simple harmonic oscillator originally written in C++ in 2008 and published in 2012. Ryan’s writeup on the subject is fantastic.

License

MIT


Part of Charm.

The Charm logo

Charm热爱开源 • Charm loves open source

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].