Skip to content

Commit e008ed7

Browse files
committed
add option for smoothing strength during interpolation
1 parent 272c9f5 commit e008ed7

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

internal/animate/interpolate.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,13 @@ export const interpolateBetween = (percentage: number, a: Shape, b: Shape): Shap
4444
return shape;
4545
};
4646

47-
// OPT smooth strength
4847
// Interpolates between shapes a and b while applying a smoothing effect. Smoothing effect's
4948
// strength is relative to how far away the percentage is from either 0 or 1. It is strongest in the
5049
// middle of the animation (percentage = 0.5) or when bounds are exceeded (percentage = 1.8).
51-
export const interpolateBetweenSmooth = (percentage: number, a: Shape, b: Shape): Shape => {
52-
const strength = Math.min(1, Math.min(Math.abs(0 - percentage), Math.abs(1 - percentage)));
50+
export const interpolateBetweenSmooth = (strength: number, percentage: number, a: Shape, b: Shape): Shape => {
51+
strength *= Math.min(1, Math.min(Math.abs(0 - percentage), Math.abs(1 - percentage)));
5352
const interpolated = interpolateBetween(percentage, a, b);
54-
const smoothed = smooth(interpolated, strength);
53+
const smoothed = smooth(interpolated, Math.sqrt(strength + 0.25)/3);
5554
return mapShape(interpolated, ({index, curr}) => {
5655
const sp = smoothed[index];
5756
curr.handleIn.angle = interpolateAngle(strength, curr.handleIn.angle, sp.handleIn.angle);

internal/animate/testing/script.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ const blob = (seed: string, count: number, scale: number, offset: Coord): Shape
185185

186186
const loopBetween = (percentage: number, a: Shape, b: Shape): Shape => {
187187
if (percentage < 0.5) {
188-
return interpolateBetweenSmooth(2 * percentage, a, b);
188+
return interpolateBetweenSmooth(1, 2 * percentage, a, b);
189189
} else {
190-
return interpolateBetweenSmooth(-2 * percentage + 2, a, b);
190+
return interpolateBetweenSmooth(1, -2 * percentage + 2, a, b);
191191
}
192192
};
193193

internal/render/canvas.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const drawPoint = (ctx: CanvasRenderingContext2D, p: Coord, style: string) => {
3131
ctx.fillStyle = backupFillStyle;
3232
};
3333

34-
// OPT draw cutout
3534
export const drawShape = (ctx: CanvasRenderingContext2D, debug: boolean, shape: Shape) => {
3635
if (shape.length < 2) throw new Error("not enough points");
3736

0 commit comments

Comments
 (0)