File tree Expand file tree Collapse file tree 3 files changed +70
-0
lines changed
app/(docs)/components/loaders/particle-swarm Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change 1+ export const metadata = {
2+ title: ' Particle Swarm Loader' ,
3+ description: ' A Particle Swarm Loader animations that moves particles in like a swarm of bees.' ,
4+ }
5+
6+ <BackButton href = " /components/loaders" />
7+ <ComponentPreview path = " components/loaders/ParticleSwarmLoader" usingFramer />
Original file line number Diff line number Diff line change 1+ 'use client'
2+
3+ import React , { useEffect , useState } from 'react'
4+ import { motion } from 'framer-motion'
5+
6+ interface ParticleProps {
7+ id : number
8+ x : number
9+ y : number
10+ size : number
11+ }
12+
13+ const ParticleSwarmLoader = ( ) => {
14+ const [ particles , setParticles ] = useState < ParticleProps [ ] > ( [ ] )
15+ const particleCount = 50
16+
17+ useEffect ( ( ) => {
18+ setParticles (
19+ Array . from ( { length : particleCount } , ( _ , i ) => ( {
20+ id : i ,
21+ x : Math . random ( ) * 200 - 100 ,
22+ y : Math . random ( ) * 200 - 100 ,
23+ size : Math . random ( ) * 4 + 2 ,
24+ } ) ) ,
25+ )
26+ } , [ ] )
27+
28+ return (
29+ < div className = "h-40 w-40 overflow-hidden rounded-full bg-transparent" >
30+ < svg width = "100%" height = "100%" viewBox = "-100 -100 200 200" >
31+ { particles . map ( ( particle ) => (
32+ < motion . circle
33+ key = { particle . id }
34+ cx = { particle . x }
35+ cy = { particle . y }
36+ r = { particle . size }
37+ fill = "#fb3a5d"
38+ initial = { { opacity : 0 } }
39+ animate = { {
40+ opacity : [ 0 , 1 , 0 ] ,
41+ cx : [ particle . x , 0 , particle . x ] ,
42+ cy : [ particle . y , 0 , particle . y ] ,
43+ } }
44+ transition = { {
45+ duration : 3 ,
46+ repeat : Infinity ,
47+ ease : 'easeInOut' ,
48+ delay : Math . random ( ) * 2 ,
49+ } }
50+ />
51+ ) ) }
52+ </ svg >
53+ </ div >
54+ )
55+ }
56+
57+ export default ParticleSwarmLoader
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import Card from './Card'
1414import WaveLoader from '../components/loaders/WaveLoader'
1515import SpiralLoader from '../components/loaders/SpiralLoader'
1616import RippleWaveLoader from '../components/loaders/RippleWaveLoader'
17+ import ParticleSwarmLoader from '../components/loaders/ParticleSwarmLoader'
1718
1819interface LoaderCardProps {
1920 title : string
@@ -90,6 +91,11 @@ const data: LoaderCardProps[] = [
9091 link : '/components/loaders/ripple-wave' ,
9192 component : < RippleWaveLoader /> ,
9293 } ,
94+ {
95+ title : 'Particle Swarm' ,
96+ link : '/components/loaders/particle-swarm' ,
97+ component : < ParticleSwarmLoader /> ,
98+ } ,
9399]
94100
95101export default function LoaderCards ( ) {
You can’t perform that action at this time.
0 commit comments