Skip to content

Commit

Permalink
fixed errors
Browse files Browse the repository at this point in the history
  • Loading branch information
0xAquaWolf committed Nov 23, 2024
1 parent 0b52b34 commit 5718a68
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions components/ui/wavy-background.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';
import { cn } from '@/lib/utils';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import React, { useCallback, useEffect, useRef, useState, useMemo } from 'react';
import { createNoise3D, NoiseFunction3D } from 'simplex-noise';

export const WavyBackground = ({
Expand Down Expand Up @@ -31,24 +31,13 @@ export const WavyBackground = ({
const ntRef = useRef<number>(0);
const animationIdRef = useRef<number>();

const getSpeed = () => {
switch (speed) {
case 'slow':
return 0.001;
case 'fast':
return 0.002;
default:
return 0.001;
}
};

const waveColors = colors ?? [
const waveColors = useMemo(() => colors ?? [
'#38bdf8',
'#818cf8',
'#c084fc',
'#e879f9',
'#22d3ee',
];
], [colors]);

const drawWave = useCallback((width: number) => {
const ctx = canvasRef.current?.getContext('2d');
Expand All @@ -74,6 +63,17 @@ export const WavyBackground = ({
const ctx = canvas?.getContext('2d');
if (!canvas || !ctx) return;

const getSpeed = () => {
switch (speed) {
case 'slow':
return 0.001;
case 'fast':
return 0.002;
default:
return 0.001;
}
};

wRef.current = canvas.width = window.innerWidth;
hRef.current = canvas.height = window.innerHeight;

Expand All @@ -97,7 +97,7 @@ export const WavyBackground = ({
};

render();
}, [blur, backgroundFill, waveOpacity, drawWave, getSpeed]);
}, [blur, backgroundFill, waveOpacity, drawWave, speed]);

useEffect(() => {
init();
Expand Down

0 comments on commit 5718a68

Please sign in to comment.