TodePond / Habitat

my javascript helpers
MIT License
45 stars 5 forks source link

Add tween function with very smooth derivatives #51

Closed Magnogen closed 2 years ago

Magnogen commented 2 years ago

I saw it in a YouTube video and thought it could go here too

TodePond commented 2 years ago

Oops I did a typo in some tests! Gonna do them again :)

TodePond commented 2 years ago

Hmm, doesn't seem to be working as intended:

Habitat.install(window);

const lu = {
    score: 20
}

const max = 10
const offset = 10
let tickTock = true
setInterval(() => {
    if (lu.score === max) return
    const count = Math.clamp(offset + lu.score, 0, Infinity)
    print(`${tickTock? "+" : "-"}${"#".repeat(count)}`)
    tickTock = !tickTock
}, 20)

lu.tween("score", {to: max, ease: Habitat.Tween.SUPER_SMOOTH})

image

TodePond commented 2 years ago

Here's a quick codepen testing out the code we can play around in: https://codepen.io/l2wilson94/pen/zYjOeXg?editors=0010

image