From 9dc908954e34b26e40a7b5cdea08b010a4ba5b56 Mon Sep 17 00:00:00 2001 From: adrianvrj Date: Mon, 2 Sep 2024 13:45:14 -0600 Subject: [PATCH 1/3] [feat] adding stardust animation on main page --- .../animations/StardustAnimation.tsx | 58 +++++++++++++++++++ frontend/gostarkme-web/app/page.tsx | 20 ++++--- .../components/welcomepage/WelcomeBar.tsx | 6 +- 3 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 frontend/gostarkme-web/animations/StardustAnimation.tsx diff --git a/frontend/gostarkme-web/animations/StardustAnimation.tsx b/frontend/gostarkme-web/animations/StardustAnimation.tsx new file mode 100644 index 0000000..5d9470e --- /dev/null +++ b/frontend/gostarkme-web/animations/StardustAnimation.tsx @@ -0,0 +1,58 @@ +import React, { useEffect, useRef } from 'react'; + +export const StardustAnimation = () => { + const canvasRef = useRef(null); + + useEffect(() => { + const canvas = canvasRef.current; + const ctx = canvas.getContext('2d'); + let animationFrameId: number; + + // Set canvas size + canvas.width = window.innerWidth; + canvas.height = window.innerHeight; + + // Create stars + const stars: { x: number; y: number; size: number; speed: number; }[] = []; + for (let i = 0; i < 200; i++) { + stars.push({ + x: Math.random() * canvas.width, + y: Math.random() * canvas.height, + size: Math.random() * 2.5, + speed: Math.random() * 0.5 + 0.2, + }); + } + + // Animation function + const animate = () => { + ctx.clearRect(0, 0, canvas.width, canvas.height); + ctx.fillStyle = 'gray'; + + stars.forEach((star) => { + ctx.beginPath(); + ctx.arc(star.x, star.y, star.size, 0, 2 * Math.PI); + ctx.fill(); + + // Move star + star.y += star.speed; + + // Reset star position if it goes off screen + if (star.y > canvas.height) { + star.y = 0; + star.x = Math.random() * canvas.width; + } + }); + + animationFrameId = requestAnimationFrame(animate); + }; + + animate(); + + // Clean up + return () => { + cancelAnimationFrame(animationFrameId); + }; + }, []); + + return ; + }; \ No newline at end of file diff --git a/frontend/gostarkme-web/app/page.tsx b/frontend/gostarkme-web/app/page.tsx index 047314f..c0b2ac4 100644 --- a/frontend/gostarkme-web/app/page.tsx +++ b/frontend/gostarkme-web/app/page.tsx @@ -1,25 +1,27 @@ +'use client' import { LinkButton } from "@/components/ui/LinkButton"; import { WelcomeBar } from "@/components/welcomepage/WelcomeBar"; import { WelcomeItems } from "@/components/welcomepage/WelcomeItems"; import Image from "next/image"; -import dotenv from 'dotenv'; +import { StardustAnimation } from "@/animations/StardustAnimation"; + export default function Home() { - dotenv.config(); - const ROOT = process.env.ROOT; + const ROOT = process.env.NEXT_PUBLIC_APP_ROOT; + return (

Upload your cause

- - - - + + + +
- + stark logo { - dotenv.config(); - const ROOT = process.env.ROOT; + const ROOT = process.env.NEXT_PUBLIC_APP_ROOT; return (