refactor: Fix formatting using prettier

This commit is contained in:
Bart van der Braak 2023-06-08 09:23:26 +02:00
parent 51f25bdc08
commit 8a5ca63a7b
27 changed files with 406 additions and 206 deletions

View file

@ -126,7 +126,18 @@ export const Particles: React.FC<ParticlesProps> = ({
const dx = (Math.random() - 0.5) * 0.2;
const dy = (Math.random() - 0.5) * 0.2;
const magnetism = 0.1 + Math.random() * 4;
return { x, y, translateX, translateY, size, alpha, targetAlpha, dx, dy, magnetism };
return {
x,
y,
translateX,
translateY,
size,
alpha,
targetAlpha,
dx,
dy,
magnetism,
};
};
const rgb = hexToRgb(color);
@ -149,7 +160,12 @@ export const Particles: React.FC<ParticlesProps> = ({
const clearContext = () => {
if (context.current) {
context.current.clearRect(0, 0, canvasSize.current.w, canvasSize.current.h);
context.current.clearRect(
0,
0,
canvasSize.current.w,
canvasSize.current.h
);
}
};
@ -167,9 +183,10 @@ export const Particles: React.FC<ParticlesProps> = ({
start1: number,
end1: number,
start2: number,
end2: number,
end2: number
): number => {
const remapped = ((value - start1) * (end2 - start2)) / (end1 - start1) + start2;
const remapped =
((value - start1) * (end2 - start2)) / (end1 - start1) + start2;
return remapped > 0 ? remapped : 0;
};
@ -184,7 +201,9 @@ export const Particles: React.FC<ParticlesProps> = ({
canvasSize.current.h - circle.y - circle.translateY - circle.size, // distance from bottom edge
];
const closestEdge = edge.reduce((a, b) => Math.min(a, b));
const remapClosestEdge = parseFloat(remapValue(closestEdge, 0, 20, 0, 1).toFixed(2));
const remapClosestEdge = parseFloat(
remapValue(closestEdge, 0, 20, 0, 1).toFixed(2)
);
if (remapClosestEdge > 1) {
circle.alpha += 0.02;
if (circle.alpha > circle.targetAlpha) {
@ -196,9 +215,11 @@ export const Particles: React.FC<ParticlesProps> = ({
circle.x += circle.dx + vx;
circle.y += circle.dy + vy;
circle.translateX +=
(mouse.current.x / (staticity / circle.magnetism) - circle.translateX) / ease;
(mouse.current.x / (staticity / circle.magnetism) - circle.translateX) /
ease;
circle.translateY +=
(mouse.current.y / (staticity / circle.magnetism) - circle.translateY) / ease;
(mouse.current.y / (staticity / circle.magnetism) - circle.translateY) /
ease;
// circle gets out of the canvas
if (
circle.x < -circle.size ||
@ -222,7 +243,7 @@ export const Particles: React.FC<ParticlesProps> = ({
translateY: circle.translateY,
alpha: circle.alpha,
},
true,
true
);
}
});