File size: 6,271 Bytes
f1c0b68 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
import React from 'react';
import ReactDOM from 'react-dom';
import { Canvas, useFrame, useThree } from '@react-three/fiber';
import { Stars, Text, Float, Sparkles, PerspectiveCamera, Environment } from '@react-three/drei';
import { useRef, useState } from 'react';
import { motion } from 'framer-motion';
// Main 3D Scene Component
function BirthdayScene() {
const meshRef = useRef();
const groupRef = useRef();
const [activeMessage, setActiveMessage] = useState(null);
const { mouse } = useThree();
const messages = [
"Your smile lights up every room",
"19 looks gorgeous on you",
"The world is better with you in it",
"Your kindness is unmatched",
"Forever young at heart",
"A soul as bright as the stars",
"Your laughter is contagious",
"Beautiful inside and out",
"A friend like no other",
"Your creativity inspires me",
"Simply one of a kind",
"The perfect blend of sweet and strong",
"Your energy is magnetic",
"A heart of pure gold",
"Wisdom beyond your years",
"Your spirit shines so bright",
"The definition of amazing",
"A light in everyone's life",
"My favorite person to celebrate"
];
useFrame((state, delta) => {
// Smooth floating animation
meshRef.current.position.y = Math.sin(state.clock.getElapsedTime() * 0.5) * 0.2;
meshRef.current.rotation.y += delta * 0.1;
// Parallax effect
groupRef.current.rotation.x = mouse.y * 0.1;
groupRef.current.rotation.y = mouse.x * 0.1;
});
return (
<group ref={groupRef}>
{/* Environment */}
<Environment preset="night" />
<Stars radius={100} depth={50} count={5000} factor={4} saturation={0} fade speed={1} />
<Sparkles count={200} scale={10} size={2} speed={0.1} color="#e2d4ff" />
{/* Main 19 Number */}
<Float speed={2} rotationIntensity={0.5} floatIntensity={1}>
<mesh ref={meshRef} position={[0, 0, 0]}>
<textGeometry args={["19", { size: 2, height: 0.5 }]} />
<meshPhysicalMaterial
transmission={0.9}
thickness={0.5}
roughness={0.1}
clearcoat={1}
clearcoatRoughness={0.1}
color="#e2d4ff"
ior={1.5}
envMapIntensity={1}
/>
</mesh>
</Float>
{/* Love Orbs */}
{Array.from({ length: 19 }).map((_, i) => {
const angle = (i / 19) * Math.PI * 2;
const radius = 4;
const x = Math.cos(angle) * radius;
const z = Math.sin(angle) * radius;
return (
<LoveOrb
key={i}
position={[x, Math.sin(angle * 2) * 0.5, z]}
message={messages[i]}
onClick={() => setActiveMessage(messages[i])}
/>
);
})}
{/* Active Message Display */}
{activeMessage && (
<Text
position={[0, -3, 0]}
color="#e0bfb8"
fontSize={0.5}
maxWidth={8}
lineHeight={1}
letterSpacing={0.02}
textAlign="center"
anchorX="center"
anchorY="middle"
>
{activeMessage}
</Text>
)}
</group>
);
}
// Love Orb Component
function LoveOrb({ position, onClick, message }) {
const meshRef = useRef();
useFrame((state) => {
meshRef.current.position.y = position[1] + Math.sin(state.clock.getElapsedTime() * 0.5 + position[0]) * 0.2;
});
return (
<mesh
ref={meshRef}
position={position}
onClick={onClick}
onPointerOver={() => document.body.style.cursor = 'pointer'}
onPointerOut={() => document.body.style.cursor = 'auto'}
>
<sphereGeometry args={[0.3, 16, 16]} />
<meshStandardMaterial
color="#e0bfb8"
emissive="#e0bfb8"
emissiveIntensity={0.5}
roughness={0.2}
metalness={0.8}
/>
</mesh>
);
}
// Main App Component
function App() {
const [entered, setEntered] = useState(false);
const handleEnter = () => {
setEntered(true);
};
return (
<>
{!entered ? (
<div className="absolute inset-0 flex items-center justify-center z-20">
<motion.div
initial={{ opacity: 1 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
className="text-center"
>
<motion.button
whileHover={{ scale: 1.05 }}
whileTap={{ scale: 0.95 }}
onClick={handleEnter}
className="px-12 py-4 bg-rose-gold-500 text-obsidian-900 rounded-full text-2xl font-medium shadow-lg"
>
ENTER HER WORLD
</motion.button>
</motion.div>
</div>
) : null}
<Canvas dpr={[1, 2]} className="h-screen w-full">
<PerspectiveCamera makeDefault position={[0, 0, 10]} fov={45} />
<ambientLight intensity={0.2} />
<pointLight position={[10, 10, 10]} intensity={1} color="#e2d4ff" />
<BirthdayScene />
</Canvas>
</>
);
}
// Wait for DOM to load before rendering
document.addEventListener('DOMContentLoaded', () => {
ReactDOM.render(<App />, document.getElementById('root'));
});
|