Skip to content

Commit

Permalink
fix: lint warning
Browse files Browse the repository at this point in the history
  • Loading branch information
kcmikee committed Nov 14, 2024
1 parent c279fd3 commit d80b62c
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions packages/nextjs/components/StarsBg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ interface StarBackgroundProps {
className?: string;
}

const createStar = (
width: number,
height: number,
allStarsTwinkle: boolean,
twinkleProbability: number,
minTwinkleSpeed: number,
maxTwinkleSpeed: number,
): StarProps => {
const shouldTwinkle = allStarsTwinkle || Math.random() < twinkleProbability;
return {
x: Math.random() * width,
y: Math.random() * height,
radius: Math.random() * 0.05 + 0.5,
opacity: Math.random() * 0.5 + 0.5,
twinkleSpeed: shouldTwinkle ? minTwinkleSpeed + Math.random() * (maxTwinkleSpeed - minTwinkleSpeed) : null,
};
};

export const StarsBackground: React.FC<StarBackgroundProps> = ({
starDensity = 0.00015,
allStarsTwinkle = true,
Expand All @@ -33,22 +51,13 @@ export const StarsBackground: React.FC<StarBackgroundProps> = ({
(width: number, height: number): StarProps[] => {
const area = width * height;
const numStars = Math.floor(area * starDensity);
return Array.from({ length: numStars }, () => createStar(width, height));
return Array.from({ length: numStars }, () =>
createStar(width, height, allStarsTwinkle, twinkleProbability, minTwinkleSpeed, maxTwinkleSpeed),
);
},
[starDensity, allStarsTwinkle, twinkleProbability, minTwinkleSpeed, maxTwinkleSpeed],
);

const createStar = (width: number, height: number): StarProps => {
const shouldTwinkle = allStarsTwinkle || Math.random() < twinkleProbability;
return {
x: Math.random() * width,
y: Math.random() * height,
radius: Math.random() * 0.05 + 0.5,
opacity: Math.random() * 0.5 + 0.5,
twinkleSpeed: shouldTwinkle ? minTwinkleSpeed + Math.random() * (maxTwinkleSpeed - minTwinkleSpeed) : null,
};
};

useEffect(() => {
const updateStars = () => {
if (canvasRef.current) {
Expand Down

0 comments on commit d80b62c

Please sign in to comment.