Skip to content

Commit

Permalink
feat: wavy progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
lovegaoshi committed Dec 12, 2023
1 parent 2244a00 commit 3c4e072
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/components/player/controls/WavyAnimation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
vec,
} from '@shopify/react-native-skia';
import { line, curveBasis } from 'd3';
import { gaussian } from '@utils/Gaussian';

const dimension = Dimensions.get('window');
const width = dimension.width;
const height = 30;
Expand Down Expand Up @@ -37,7 +39,8 @@ export default function WaveAnimation({
const angle = (index / width) * (Math.PI * frequency) + phase;
return [
index,
amplitude.current * Math.sin(angle) + verticalOffset.current + 10,
(amplitude.current * Math.sin(angle) + verticalOffset.current + 10) *
gaussian(index / width),
];
}
);
Expand Down
3 changes: 3 additions & 0 deletions src/utils/Gaussian.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// e^(-(x - 0.5)² / 2*5²)
export const gaussian = (x: number, a = 1, b = 0.5, c = 5) =>
Math.pow(Math.E, (a * -Math.pow(x - b, 2)) / (2 * Math.pow(c, 2)));

0 comments on commit 3c4e072

Please sign in to comment.