Skip to content

Commit

Permalink
Migrate to jsr
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne-dldc committed May 5, 2024
1 parent ad85f15 commit 58777da
Show file tree
Hide file tree
Showing 48 changed files with 1,023 additions and 36,610 deletions.
4 changes: 0 additions & 4 deletions .dldc.json

This file was deleted.

22 changes: 22 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Publish

on:
push:
branches:
- main

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # The OIDC ID token is used for authentication with JSR.
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x # Run with latest stable Deno.

- run: deno task check

- run: npx jsr publish
1 change: 0 additions & 1 deletion .node-version

This file was deleted.

1 change: 0 additions & 1 deletion .prettierignore

This file was deleted.

6 changes: 0 additions & 6 deletions .prettierrc.json

This file was deleted.

15 changes: 0 additions & 15 deletions .release-it.json

This file was deleted.

5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"eslint.useFlatConfig": true
"deno.enable": true,
"editor.defaultFormatter": "denoland.vscode-deno",
"npm.autoDetect": "off"
}
51 changes: 35 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,26 @@ npm install @dldc/humpf

## What is this

This a library that let you animate using a [Damped Springs](http://www.ryanjuckett.com/programming/damped-springs/). The awesome thing about springs is that they can model all king of motions:
This a library that let you animate using a
[Damped Springs](http://www.ryanjuckett.com/programming/damped-springs/). The
awesome thing about springs is that they can model all king of motions:

- ✅ From A to B with a rebound at the end
- ✅ From A to B smoothly
- ✅ Decay (like pushing something)

## Difference with other libraries

Most library out there will model spring by updating a value: on each frame they compute the forces applyed on the value and upate it accordingly.
Humpf is different because it does not update a value but give you a function that take the **time** as parameter and return the **position** and **velocity** (speed) at that position in time.
Most library out there will model spring by updating a value: on each frame they
compute the forces applyed on the value and upate it accordingly. Humpf is
different because it does not update a value but give you a function that take
the **time** as parameter and return the **position** and **velocity** (speed)
at that position in time.

## Gist

```ts
import { Spring } from '@dldc/humpf';
import { Spring } from "@dldc/humpf";

const spring = Spring();

Expand Down Expand Up @@ -58,41 +63,55 @@ Spring({

### `position` (default `0`)

This is the initiale position of the spring: the value when it starts (at `timeStart`).
This is the initiale position of the spring: the value when it starts (at
`timeStart`).

### `equilibrium` (default `100`)

The equilibrium position of the spring: the value it will reach over time. If your spring bounce it will occilate around this value.
The equilibrium position of the spring: the value it will reach over time. If
your spring bounce it will occilate around this value.

### `velocity` (default `0`)

The initial velocity of the spring. `0` mean it's stationary.

**Example**: If your spring goes from `0` to `100`, a positive `velocity` mean it's already going up so it will go faster. A negative velocity means it's going in the oposite direction and will go down a little before going up.
**Example**: If your spring goes from `0` to `100`, a positive `velocity` mean
it's already going up so it will go faster. A negative velocity means it's going
in the oposite direction and will go down a little before going up.

### `angularFrequency` (default `0`)

The angular frequency of your spring define how fast it wants to move. If you have a very bouncy spring (not much friction), the angular frequency define how many back and forth will happen.
The angular frequency of your spring define how fast it wants to move. If you
have a very bouncy spring (not much friction), the angular frequency define how
many back and forth will happen.

**Example**: `10` mean a lot of back and forth, so your spring will move fast. `0.5` is much lower so your spring will be slower
**Example**: `10` mean a lot of back and forth, so your spring will move fast.
`0.5` is much lower so your spring will be slower

### `dampingRatio` (default `1`)

The damping ratio define how much resistance (friction) is opposed to your spring.
If the damping ratio is less than `1` your spring will overshoot and bounce. If it's under `1` it will not.
If the damping ratio is `1` it will reach the equilibrium as fast as possible without bouncing.
The damping ratio define how much resistance (friction) is opposed to your
spring.\
If the damping ratio is less than `1` your spring will overshoot and bounce. If
it's under `1` it will not.\
If the damping ratio is `1` it will reach the equilibrium as fast as possible
without bouncing.

### `timeStart` (default `0`)

The time at which the spring should start.
The time at which the spring should start.\
Usually you want to pass the current time to start a spring "now".

**Note**: spring does not work in reverse, so you you try to get a value for a time before `timeStart` it will return the initial state.
**Note**: spring does not work in reverse, so you you try to get a value for a
time before `timeStart` it will return the initial state.

### `timeScale` (default `1 / 100`)

The `timeScale` allow you to change how time is interpreted. The default value `1/100` will make your spring to take about a second to reach equilibrium. You probably don't need to change this.
The `timeScale` allow you to change how time is interpreted. The default value
`1/100` will make your spring to take about a second to reach equilibrium. You
probably don't need to change this.

## Math equations

Most of the maths come from http://www.ryanjuckett.com/programming/damped-springs/.
Most of the maths come from
http://www.ryanjuckett.com/programming/damped-springs/.
21 changes: 21 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@dldc/humpf",
"version": "7.0.0",
"exports": "./mod.ts",
"imports": {
"$std/": "https://deno.land/std@0.224.0/",
"$canvas/": "https://deno.land/x/canvas@v1.4.1/",
"@dldc/erreur": "jsr:@dldc/erreur@^7.1.1"
},
"tasks": {
"test": "deno test -A",
"test:watch": "deno test --watch",
"bump": "deno run -A jsr:@mys/bump@1",
"update": "deno run --allow-read=. --allow-write=. --allow-net https://deno.land/x/udd@0.8.2/main.ts *.ts deno.jsonc",
"check": "deno fmt --check . && deno lint . && deno task test"
},
"lint": {
"rules": { "exclude": ["no-explicit-any"] }
},
"exclude": ["tests/data"]
}
Loading

0 comments on commit 58777da

Please sign in to comment.