2021-07-13 20:51:16 -04:00
2021-07-09 15:55:54 -04:00
2021-07-13 20:51:16 -04:00
2021-07-09 13:12:47 -04:00
2021-07-13 20:40:54 -04:00
2021-07-13 20:39:37 -04:00
2021-07-09 13:12:59 -04:00
2021-07-09 15:00:26 -04:00

Harmonica

Latest Release GoDoc Build Status

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

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.FPS60, 0.8, 0.98)

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

For details, see the examples and the docs.

Acknowledgements

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

License

MIT


Part of Charm.

The Charm logo

Charm热爱开源 • Charm loves open source

Description
A simple, physics-based animation library 🎼
Readme MIT 377 KiB
Languages
Go 100%