npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@internet/spring

v0.0.3

Published

Framerate-independant spring physics

Downloads

19

Readme

:wavy_dash: Spring

:books: Documentation | :tada: Example | :globe_with_meridians: Internet modules

Requirements

API

new Spring([options])

Create a new Spring instance.

| Param | Type | Default | Description | | --- | --- | --- | --- | | [options] | Object | {} | Spring options. | | [options.initial] | number | 0 | Initial value / targetValue of your spring. | | [options.tension] | number | 0.1 | Tension/Stifness of your spring. | | [options.friction] | number | 0.2 | From 0 to 1. Friction (Damping) of your spring. | | [options.step] | number | 10 | Timestep of the physics solver (in ms). Step > 16.67ms will give you pretty bad results. | | [options.onStart] | function | | onStart will be called when the spring starts moving. | | [options.onStop] | function | | onStop will be called when your the spring stops moving. | | [options.precisionStop] | number | 0.0001 | Minimum distance between value and target to consider the spring stopped. | | [options.perfectStop] | boolean | false | Define if value is set precisely to targetValue when the spring stops moving. |

Example

import { raf } from '@internet/raf'
import Spring from '@internet/spring'

const move = new Spring({ initial: 0 })
move.setTarget(300)
raf.add(dt => {
  move.update(dt)
  console.log(move.value)
})

spring.setValue(newCurrent)

Change the current position of the spring. Can retrigger onStart / onStop.

Kind: instance method of Spring
Category: Methods

| Param | Type | Description | | --- | --- | --- | | newCurrent | number | New current value. |


spring.setTarget(newTarget)

Update target / resting position of the spring. Can retrigger onStart / onStop.

Kind: instance method of Spring
Category: Methods

| Param | Type | Description | | --- | --- | --- | | newTarget | number | New target value. |


spring.setTension(tensionValue)

Update tension of the spring

Kind: instance method of Spring
Category: Methods

| Param | Type | Description | | --- | --- | --- | | tensionValue | number | New tension value. |


spring.setFriction(frictionValue)

Update friction of the spring

Kind: instance method of Spring
Category: Methods

| Param | Type | Description | | --- | --- | --- | | frictionValue | number | New friction value. |


spring.start()

Force re-start of the spring. Only needed if you force-stop the spring with stop()

Kind: instance method of Spring
Category: Methods


spring.stop()

Force-stop the spring.

Kind: instance method of Spring
Category: Methods


spring.update(dt)

Update the spring physic state

Kind: instance method of Spring
Category: Methods

| Param | Type | Description | | --- | --- | --- | | dt | number | Elapsed time since the last frame (in ms) |


spring.dispose()

Stop the spring and remove callbacks referenced in onStart and onStop.

Kind: instance method of Spring
Category: Methods


spring.initial : number

Initial position of the spring

Kind: instance property of Spring
Category: Properties


spring.value : number

Current position of the spring

Kind: instance property of Spring
Category: Properties


spring.previous : number

Previous frame position of the spring

Kind: instance property of Spring
Category: Properties


spring.velocity : number

Current velocity of the spring

Kind: instance property of Spring
Category: Properties


spring.onStart : function

Optional function called when the spring starts

Kind: instance property of Spring
Category: Properties


spring.onStop : function

Optional function called when the spring stops

Kind: instance property of Spring
Category: Properties