-
Notifications
You must be signed in to change notification settings - Fork 98
added the particle design at the background #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughA new Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant PageComponent (Landing/Legal/Privacy)
participant ParticleEffect
User->>PageComponent: Loads page
PageComponent->>ParticleEffect: Render ParticleEffect
ParticleEffect->>ParticleEffect: Initialize particles & animation
loop Animation frame
ParticleEffect->>ParticleEffect: Update & draw particles
ParticleEffect->>ParticleEffect: Handle mouse interaction (if enabled)
end
PageComponent->>User: Render rest of page content
Estimated code review effort3 (~45 minutes) Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (2)
LandingPage/src/components/ParticleCanva.tsx (2)
71-97: Consider caching gradients for better performance.Creating a new radial gradient for each particle on every frame can be expensive. Consider pre-generating gradients or using a simpler rendering approach for better performance.
204-210: Consider making z-index configurable.The fixed z-index of 10 might conflict with other page elements. Consider making it a prop for better flexibility across different pages.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
LandingPage/src/Pages/Landing.tsx(2 hunks)LandingPage/src/Pages/Legal.tsx(2 hunks)LandingPage/src/Pages/Privacy.tsx(2 hunks)LandingPage/src/components/ParticleCanva.tsx(1 hunks)
🔇 Additional comments (6)
LandingPage/src/components/ParticleCanva.tsx (3)
1-30: Well-structured component setup with proper TypeScript interfaces.The interfaces are well-defined and the component uses appropriate React patterns with refs for performance-critical operations.
43-63: Particle initialization logic is correct.The particle creation with randomized properties provides good visual variety.
164-202: Proper animation loop implementation with correct cleanup.The animation uses requestAnimationFrame correctly and includes comprehensive cleanup to prevent memory leaks.
LandingPage/src/Pages/Privacy.tsx (1)
5-5: Clean integration of ParticleEffect component.The particle effect is properly integrated as a background element.
Also applies to: 14-15
LandingPage/src/Pages/Legal.tsx (1)
5-5: Consistent integration with other pages.The particle effect implementation matches the pattern used in other pages.
Also applies to: 15-15
LandingPage/src/Pages/Landing.tsx (1)
11-11: Verify the need for two particle effects on the same page.The Landing page already has a
Threadscomponent (lines 59-65) that appears to be another particle/animation effect. Having bothParticleEffectandThreadsmight impact performance and create visual clutter.Consider whether both effects are necessary or if they should be combined into a single, more performant solution.
Also applies to: 33-33
| particle.x += Math.sin(Date.now() * 0.001 + particle.y * 0.01) * 0.1; | ||
| particle.y += Math.cos(Date.now() * 0.001 + particle.x * 0.01) * 0.1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using Date.now() in animation calculations.
Using Date.now() in the floating motion calculation can cause performance issues as it's called for every particle on every frame. Consider using a frame counter or elapsed time instead.
Apply this diff to improve performance:
+ const animationRef = useRef<number>(0);
+ const timeRef = useRef<number>(0);
// In animate function:
+ timeRef.current += 0.016; // Approximate 60fps
// In updateParticle:
- particle.x += Math.sin(Date.now() * 0.001 + particle.y * 0.01) * 0.1;
- particle.y += Math.cos(Date.now() * 0.001 + particle.x * 0.01) * 0.1;
+ particle.x += Math.sin(timeRef.current + particle.y * 0.01) * 0.1;
+ particle.y += Math.cos(timeRef.current + particle.x * 0.01) * 0.1;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| particle.x += Math.sin(Date.now() * 0.001 + particle.y * 0.01) * 0.1; | |
| particle.y += Math.cos(Date.now() * 0.001 + particle.x * 0.01) * 0.1; | |
| particle.x += Math.sin(timeRef.current + particle.y * 0.01) * 0.1; | |
| particle.y += Math.cos(timeRef.current + particle.x * 0.01) * 0.1; |
🤖 Prompt for AI Agents
In LandingPage/src/components/ParticleCanva.tsx around lines 122 to 123, replace
the use of Date.now() in the particle position updates with a frame counter or
elapsed time variable that updates once per animation frame. This avoids calling
Date.now() for every particle on every frame, improving performance. Introduce a
time variable outside the particle loop that increments each frame and use it in
the sine and cosine calculations instead of Date.now().
| const drawConnections = () => { | ||
| const particles = particlesRef.current; | ||
| ctx.strokeStyle = 'rgba(147, 0, 160, 0.1)'; | ||
| ctx.lineWidth = 0.5; | ||
|
|
||
| for (let i = 0; i < particles.length; i++) { | ||
| for (let j = i + 1; j < particles.length; j++) { | ||
| const dx = particles[i].x - particles[j].x; | ||
| const dy = particles[i].y - particles[j].y; | ||
| const distance = Math.sqrt(dx * dx + dy * dy); | ||
|
|
||
| if (distance < 100) { | ||
| const opacity = (100 - distance) / 100 * 0.3; | ||
| ctx.globalAlpha = opacity; | ||
| ctx.beginPath(); | ||
| ctx.moveTo(particles[i].x, particles[i].y); | ||
| ctx.lineTo(particles[j].x, particles[j].y); | ||
| ctx.stroke(); | ||
| } | ||
| } | ||
| } | ||
| ctx.globalAlpha = 1; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
O(n²) complexity in connection drawing may impact performance.
The nested loop for drawing connections has quadratic complexity. With the default 50 particles, this results in 1,225 distance calculations per frame. Consider implementing spatial partitioning or limiting connections to improve performance on lower-end devices.
🤖 Prompt for AI Agents
In LandingPage/src/components/ParticleCanva.tsx around lines 140 to 162, the
nested loops for drawing connections have O(n²) complexity, causing performance
issues with many particles. To fix this, implement spatial partitioning
techniques like a grid or quadtree to limit distance checks only to nearby
particles, or restrict the maximum number of connections per particle. This will
reduce the number of distance calculations and improve rendering performance on
lower-end devices.
Summary by CodeRabbit