From 242e12be89688a71382a10e7aba57a21adf3e4b6 Mon Sep 17 00:00:00 2001 From: Yash8077 Date: Thu, 31 Oct 2024 19:02:30 +0530 Subject: [PATCH] feat: Add TestEffects page for cursor effects --- chaosweb-v@2/src/App.jsx | 2 + chaosweb-v@2/src/components/navbar.jsx | 3 ++ chaosweb-v@2/src/pages/ColorEffect.css | 59 ++++++++++++++++++++++++++ chaosweb-v@2/src/pages/TestEffects.jsx | 48 +++++++++++++++++++++ 4 files changed, 112 insertions(+) create mode 100644 chaosweb-v@2/src/pages/ColorEffect.css create mode 100644 chaosweb-v@2/src/pages/TestEffects.jsx diff --git a/chaosweb-v@2/src/App.jsx b/chaosweb-v@2/src/App.jsx index e4a14cb..bcf71b6 100644 --- a/chaosweb-v@2/src/App.jsx +++ b/chaosweb-v@2/src/App.jsx @@ -13,6 +13,7 @@ import { useState } from "react"; import JumpScareEffect from "./components/JumpScareEffect"; import BarrelRoll from "./pages/BarrelRoll"; import RateUs from "./pages/RateUs"; +import TestEffects from "./pages/TestEffects"; function App() { const [trigger, setTrigger] = useState(false); @@ -44,6 +45,7 @@ function App() { } /> } /> } /> + } /> diff --git a/chaosweb-v@2/src/components/navbar.jsx b/chaosweb-v@2/src/components/navbar.jsx index 47fe94f..0d5918d 100644 --- a/chaosweb-v@2/src/components/navbar.jsx +++ b/chaosweb-v@2/src/components/navbar.jsx @@ -1671,6 +1671,9 @@ const Navbar = () => {
handleNavigate("/maze")}> Maze Game
+
handleNavigate("/coloreffects")}> + Cursor Effects !! +
handleNavigate("/chaosmania")}> ChaosMania
diff --git a/chaosweb-v@2/src/pages/ColorEffect.css b/chaosweb-v@2/src/pages/ColorEffect.css new file mode 100644 index 0000000..1aed7f9 --- /dev/null +++ b/chaosweb-v@2/src/pages/ColorEffect.css @@ -0,0 +1,59 @@ +.color-effect-container { + position: absolute; + top:0px; + left:0px; + width: 100vw; + height: 100vh; + overflow: hidden; + cursor: pointer; + } + + .effect { + position: absolute; + pointer-events: none; + } + + .splash { + width: 10px; + height: 10px; + border-radius: 50%; + animation: splashAnimation 1s ease-out forwards; + opacity: 0.8; + } + + .shatter { + width: 0; + height: 0; + border-left: 10px solid transparent; + border-right: 10px solid transparent; + border-bottom: 20px solid; + animation: shatterAnimation 1s ease-out forwards; + opacity: 0.8; + } + + @keyframes splashAnimation { + 0% { + transform: scale(1); + opacity: 1; + } + 50% { + transform: scale(2); + opacity: 0.7; + } + 100% { + transform: scale(0.5); + opacity: 0; + } + } + + @keyframes shatterAnimation { + 0% { + transform: scale(1) rotate(0deg); + opacity: 1; + } + 100% { + transform: scale(1.5) translate(50px, 50px) rotate(180deg); + opacity: 0; + } + } + \ No newline at end of file diff --git a/chaosweb-v@2/src/pages/TestEffects.jsx b/chaosweb-v@2/src/pages/TestEffects.jsx new file mode 100644 index 0000000..b4183a9 --- /dev/null +++ b/chaosweb-v@2/src/pages/TestEffects.jsx @@ -0,0 +1,48 @@ +import React, { useState } from "react"; +import "./ColorEffect.css"; + +const TestEffects = () => { + const [effects, setEffects] = useState([]); + + const handleClick = (e) => { + const { clientX: x, clientY: y } = e; + + const isShatter = Math.random() > 0.5; + const newEffects = Array.from({ length: 50 }).map(() => ({ + x, + y, + offsetX: isShatter ? (Math.random() - 0.5) * 300 : (Math.random() - 0.5) * 300, + offsetY: isShatter ? (Math.random() - 0.5) * 300 : (Math.random() - 0.5) * 300, + rotation: isShatter ? Math.random() * 360 : 0, + color: `hsl(${Math.random() * 360}, 100%, 50%)`, + id: Math.random(), + type: isShatter ? "shatter" : "splash", + })); + + setEffects((prev) => [...prev, ...newEffects]); + + setTimeout(() => { + setEffects((prev) => prev.slice(newEffects.length)); + }, 1000); + }; + + return ( +
+ {effects.map(({ x, y, offsetX, offsetY, rotation, color, id, type }) => ( +
+ ))} +

Click anywhere for a random color effect!

+
+ ); +}; + +export default TestEffects;