-
-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f15dae4
commit 8778a16
Showing
11 changed files
with
482 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { steps } from "../steps" | ||
|
||
test("steps", () => { | ||
const stepEnd = steps(4) | ||
|
||
expect(stepEnd(0)).toBe(0) | ||
expect(stepEnd(0.2)).toBe(0) | ||
expect(stepEnd(0.249)).toBe(0) | ||
expect(stepEnd(0.25)).toBe(0.25) | ||
expect(stepEnd(0.49)).toBe(0.25) | ||
expect(stepEnd(0.5)).toBe(0.5) | ||
expect(stepEnd(0.99)).toBe(0.75) | ||
expect(stepEnd(1)).toBe(0.75) | ||
|
||
const stepStart = steps(4, "start") | ||
expect(stepStart(0)).toBe(0.25) | ||
expect(stepStart(0.2)).toBe(0.25) | ||
expect(stepStart(0.249)).toBe(0.25) | ||
expect(stepStart(0.25)).toBe(0.25) | ||
expect(stepStart(0.49)).toBe(0.5) | ||
expect(stepStart(0.5)).toBe(0.5) | ||
expect(stepStart(0.51)).toBe(0.75) | ||
expect(stepStart(0.99)).toBe(1) | ||
expect(stepStart(1)).toBe(1) | ||
expect(stepStart(2)).toBe(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { clamp } from "../utils/clamp" | ||
import type { EasingFunction } from "./types" | ||
|
||
/* | ||
Create stepped version of 0-1 progress | ||
@param [int]: Number of steps | ||
@param [number]: Current value | ||
@return [number]: Stepped value | ||
*/ | ||
export type Direction = "start" | "end" | ||
|
||
export function steps( | ||
numSteps: number, | ||
direction: Direction = "end" | ||
): EasingFunction { | ||
return (progress: number) => { | ||
progress = | ||
direction === "end" | ||
? Math.min(progress, 0.999) | ||
: Math.max(progress, 0.001) | ||
const expanded = progress * numSteps | ||
const rounded = | ||
direction === "end" ? Math.floor(expanded) : Math.ceil(expanded) | ||
|
||
return clamp(0, 1, rounded / numSteps) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.