Skip to content

Commit

Permalink
add particle effect
Browse files Browse the repository at this point in the history
  • Loading branch information
pwang1997 committed Oct 5, 2024
1 parent 8f0d290 commit 7f1fbad
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 13 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@trpc/client": "next",
"@trpc/react-query": "next",
"@trpc/server": "next",
"@tsparticles/react": "^3.0.0",
"@uiw/react-md-editor": "^4.0.4",
"@vercel/analytics": "^1.3.1",
"@vercel/speed-insights": "^1.0.12",
Expand All @@ -63,6 +64,7 @@
"superjson": "^2.2.1",
"tailwind-merge": "^2.5.2",
"tailwindcss-animate": "^1.0.7",
"tsparticles": "^3.5.0",
"typed.js": "^2.1.0",
"zod": "^3.23.8"
},
Expand Down
108 changes: 108 additions & 0 deletions src/app/(client)/Particles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
"use client";

import {
type Container,
type ISourceOptions,
MoveDirection,
OutMode,
} from "@tsparticles/engine";
import Particles, { initParticlesEngine } from "@tsparticles/react";
import { useEffect, useMemo, useState } from "react";
import { loadFull } from "tsparticles";

export const MyParticles = () => {
const [init, setInit] = useState(false);

// this should be run only once per application lifetime
useEffect(() => {
void initParticlesEngine(async (engine) => {
await loadFull(engine);
}).then(() => {
setInit(true);
});
}, []);

const particlesLoaded = async (container?: Container): Promise<void> => {
console.log(container);
};

const options: ISourceOptions = useMemo(
() => {
return ({
fpsLimit: 120,
interactivity: {
events: {
// onClick: {
// enable: true,
// mode: "push",
// },
// onHover: {
// enable: true,
// mode: "repulse",
// },
},
modes: {
push: {
quantity: 4,
},
repulse: {
distance: 200,
duration: 0.4,
},
},
},
particles: {
color: {
value: "#000000",
},
links: {
color: "#000000",
distance: 150,
enable: true,
opacity: 0.2,
width: 1,
},
move: {
direction: MoveDirection.none,
enable: true,
outModes: {
default: OutMode.out,
},
random: false,
speed: 6,
straight: false,
},
number: {
density: {
enable: true,
},
value: 30,
},
opacity: {
value: 0.2,
},
shape: {
type: "circle",
},
size: {
value: { min: 1, max: 5 },
},
},
detectRetina: true,
});
},
[],
);

if (init) {
return (
<Particles
id="tsparticles"
particlesLoaded={particlesLoaded}
options={options}
/>
);
}

return <></>;
};
2 changes: 2 additions & 0 deletions src/app/(client)/about/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import LinkedInIcon from '~/icons/LinkedInIcon';
import MapPinIcon from '~/icons/MapPinIcon';
import MediumIcon from '~/icons/MediumIcon';
import UserIcon from '~/icons/UserIcon';
import { MyParticles } from '../Particles';
import DownloadableFileItem from './_components/DownloadableFileItem';
import Timeline from './_components/Timeline';

export default async function AboutPage() {
return (
<div>
<MyParticles />
<div className='mt-6 border-t border-gray-100'>
<dl className='divide-y divide-gray-100'>
<div className='px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 animate-[fadeIn_2s_ease-in-out]'>
Expand Down
30 changes: 17 additions & 13 deletions src/app/(client)/developer-notes/page.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { MyParticles } from "../Particles";
import notes from "./site-notes";

export default function Page() {
return (
<div className="dark:bg-medium dark:text-white">
<div className='max-w-md divide-y divide-gray-200 text-gray-900 dark:divide-gray-700 dark:text-white min-w-full py-6'>
{
notes.map((item: { date: string, text: string }) => {
return (
<div key={item.date} className='flex flex-col pb-3'>
<dt className='mb-1 text-gray-500 md:text-lg dark:text-gray-400'>{item.date}</dt>
<dd className='text-lg font-semibold'>{item.text}</dd>
</div>
)
})
}
<>
<MyParticles />
<div className="dark:bg-medium dark:text-white">
<div className='max-w-md divide-y divide-gray-200 text-gray-900 dark:divide-gray-700 dark:text-white min-w-full py-6'>
{
notes.map((item: { date: string, text: string }) => {
return (
<div key={item.date} className='flex flex-col pb-3'>
<dt className='mb-1 text-gray-500 md:text-lg dark:text-gray-400'>{item.date}</dt>
<dd className='text-lg font-semibold'>{item.text}</dd>
</div>
)
})
}
</div>
</div>
</div>
</>
);
}
2 changes: 2 additions & 0 deletions src/app/(client)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import HeroSection from "../_components/hero-section";
import ShareSpace from "../_components/share-space";
import WhereToFindMe from "../_components/where-to-find-me";
import { MyParticles } from "./Particles";

export default async function Home() {

return (
<main>
<MyParticles />
<div className='mx-1 sm:pt-0 grid gap-y-8 place-content-center'>
<div className="sm:pt-0">
<HeroSection />
Expand Down

0 comments on commit 7f1fbad

Please sign in to comment.