File size: 8,007 Bytes
6c44a41 586831e | 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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D Particle Animation</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<style>
body {
margin: 0;
overflow: hidden;
background-color: #000;
}
canvas {
display: block;
}
.loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
font-family: 'Arial', sans-serif;
font-size: 24px;
}
.ui-overlay {
position: absolute;
bottom: 2rem;
left: 50%;
transform: translateX(-50%);
color: white;
text-align: center;
font-family: 'Arial', sans-serif;
z-index: 100;
}
.controls {
position: absolute;
top: 2rem;
right: 2rem;
z-index: 100;
display: flex;
gap: 1rem;
}
.control-btn {
background: rgba(255,255,255,0.2);
border: none;
color: white;
width: 40px;
height: 40px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: all 0.3s ease;
}
.control-btn:hover {
background: rgba(255,255,255,0.4);
}
</style>
</head>
<body>
<div class="loading">Loading...</div>
<div class="ui-overlay" id="uiOverlay">
<h1 class="text-4xl font-bold mb-2">S N X</h1>
<p class="opacity-80">Interactive 3D particle experience</p>
</div>
<div class="controls">
<button class="control-btn" id="colorBtn">
<i data-feather="droplet"></i>
</button>
<button class="control-btn" id="sizeBtn">
<i data-feather="maximize-2"></i>
</button>
<button class="control-btn" id="resetBtn">
<i data-feather="refresh-cw"></i>
</button>
</div>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<script>
// Scene setup
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(window.devicePixelRatio);
document.body.appendChild(renderer.domElement);
// Remove loading text
document.querySelector('.loading').remove();
feather.replace();
// Particle setup
const particleGeometry = new THREE.BufferGeometry();
const particleCount = 15000;
const posArray = new Float32Array(particleCount * 3);
for(let i = 0; i < particleCount * 3; i++) {
posArray[i] = (Math.random() - 0.5) * 15;
}
particleGeometry.setAttribute('position', new THREE.BufferAttribute(posArray, 3));
const particleMaterial = new THREE.PointsMaterial({
size: 0.03,
color: 0xffffff,
transparent: true,
opacity: 1,
blending: THREE.AdditiveBlending
});
const particles = new THREE.Points(particleGeometry, particleMaterial);
scene.add(particles);
// Text setup
const fontLoader = new THREE.FontLoader();
fontLoader.load('https://threejs.org/examples/fonts/helvetiker_regular.typeface.json', (font) => {
const textGeometry = new THREE.TextGeometry('S N X', {
font: font,
size: 0.8,
height: 0.3,
curveSegments: 12,
bevelEnabled: true,
bevelThickness: 0.05,
bevelSize: 0.03,
bevelOffset: 0,
bevelSegments: 5
});
const textMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
wireframe: true,
transparent: true,
opacity: 1.5
});
const textMesh = new THREE.Mesh(textGeometry, textMaterial);
// Positioning text in the center
textGeometry.computeBoundingBox();
const textWidth = textGeometry.boundingBox.max.x - textGeometry.boundingBox.min.x;
textMesh.position.set(-textWidth / 2, -0.5, 0);
// Add subtle duplicate text behind
const textMaterial2 = new THREE.MeshBasicMaterial({
color: 0xffffff,
wireframe: true,
transparent: true,
opacity: 0.5
});
scene.add(textMesh);
});
// Camera position
camera.position.z = 5;
// Animation variables
let rotationSpeedX = 0.0005;
let rotationSpeedY = 0.001;
let isAnimating = true;
// Animation loop
function animate() {
requestAnimationFrame(animate);
if(isAnimating) {
particles.rotation.x += rotationSpeedX;
particles.rotation.y += rotationSpeedY;
}
renderer.render(scene, camera);
}
animate();
// Handle window resize
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
// UI Controls
const colorBtn = document.getElementById('colorBtn');
const sizeBtn = document.getElementById('sizeBtn');
const resetBtn = document.getElementById('resetBtn');
const uiOverlay = document.getElementById('uiOverlay');
const colors = [
0xffffff, // white
0xffffff, // white
0xffffff, // white
0xffffff, // white
0xffffff // white
];
let colorIndex = 0;
colorBtn.addEventListener('click', () => {
colorIndex = (colorIndex + 1) % colors.length;
particleMaterial.color.setHex(colors[colorIndex]);
});
sizeBtn.addEventListener('click', () => {
particleMaterial.size = particleMaterial.size === 0.03 ? 0.1 : 0.03;
});
resetBtn.addEventListener('click', () => {
particleMaterial.color.setHex(0xffffff);
particleMaterial.size = 0.03;
colorIndex = 0;
});
// Mouse interaction
let mouseX = 0;
let mouseY = 0;
document.addEventListener('mousemove', (event) => {
mouseX = (event.clientX / window.innerWidth) * 2 - 1;
mouseY = -(event.clientY / window.innerHeight) * 2 + 1;
// Update rotation speeds based on mouse position
rotationSpeedX = mouseY * 0.002;
rotationSpeedY = mouseX * 0.002;
});
// Hide UI after 5 seconds
setTimeout(() => {
uiOverlay.style.opacity = '0';
uiOverlay.style.transition = 'opacity 1s ease';
}, 5000);
// Show UI on mouse move
document.addEventListener('mousemove', () => {
uiOverlay.style.opacity = '1';
clearTimeout(uiTimeout);
uiTimeout = setTimeout(() => {
uiOverlay.style.opacity = '0';
}, 3000);
});
let uiTimeout;
</script>
</body>
</html>
|