-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use bezier-js instead of bezier-easing and update API
- Loading branch information
1 parent
94d50a1
commit 231a9ff
Showing
14 changed files
with
1,660 additions
and
3,849 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 |
---|---|---|
@@ -1,43 +1,13 @@ | ||
'use strict' | ||
Object.defineProperty(exports, '__esModule', { value: true }) | ||
const BezierEasing = require('bezier-easing') | ||
const Bezier = require('bezier-js') | ||
// import { Bezier } from 'bezier-js' | ||
// import * as Bezier from 'bezier-js' | ||
const shared = require('./shared') | ||
function cubicCoordinates(x1, y1, x2, y2, hypotSize = 0.1, incrementSize = 0.001) { | ||
const bezier = BezierEasing(x1, y1, x2, y2) | ||
let x = 0 | ||
let y = 0 | ||
let xOld = 0 | ||
let yOld = 0 | ||
let firstTime = true | ||
let coordinates = [] | ||
// After first time test if distance from last coordinate added in inner loop (xOld, yOld) to (1, 1) is within 90% of average distance between coordinates | ||
while (firstTime || Math.hypot(1 - xOld, 1 - yOld) < hypotSize * 0.9) { | ||
if (firstTime) { | ||
firstTime = false | ||
} else { | ||
// Decrease hypotSize by incrementSize and reset values | ||
hypotSize -= incrementSize | ||
x = 0 | ||
y = 0 | ||
xOld = 0 | ||
yOld = 0 | ||
coordinates = [] | ||
} | ||
// Add the first coordinate | ||
coordinates.push(shared.getCoordinate(0, 0)) | ||
// Loop and add coordinates every time it's far enough away from the previous one | ||
while (x <= 1) { | ||
y = bezier(x) | ||
if (Math.hypot(x - xOld, y - yOld) > hypotSize) { | ||
coordinates.push(shared.getCoordinate(x, y)) | ||
xOld = x | ||
yOld = y | ||
} | ||
x += incrementSize | ||
} | ||
// Add the last coordinate | ||
coordinates.push(shared.getCoordinate(1, 1)) | ||
} | ||
return coordinates | ||
function cubicCoordinates(x1, y1, x2, y2, steps = 10) { | ||
const curve = new Bezier(0, 0, x1, y1, x2, y2, 1, 1) | ||
const coordinates = curve.getLUT(steps) | ||
const roundedCoordinates = coordinates.map(obj => shared.getCoordinate(obj.x, obj.y)) | ||
return roundedCoordinates | ||
} | ||
exports.cubicCoordinates = cubicCoordinates |
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 |
---|---|---|
@@ -1,9 +1,5 @@ | ||
import { cubicCoordinates } from './lib/cubic-coordinates' | ||
import * as shared from './lib/shared' | ||
import { stepsCoordinates } from './lib/steps-coordinates' | ||
declare function easingCoordinates( | ||
easingFunction: string, | ||
hypotSize?: number, | ||
incrementSize?: number | ||
): shared.ICoordinate[] | ||
declare function easingCoordinates(easingFunction: string, steps?: number): shared.ICoordinate[] | ||
export { stepsCoordinates, cubicCoordinates, easingCoordinates, easingCoordinates as default } |
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.