166 lines
7.2 KiB
HTML
166 lines
7.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>14 - VORTEX | 龙卷风</title>
|
|
<style>
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
body { background: #000; overflow: hidden; font-family: 'Space Mono', monospace; }
|
|
#canvas-container { width: 100vw; height: 100vh; }
|
|
.info {
|
|
position: fixed; top: 20px; left: 20px; color: #22d3ee;
|
|
font-size: 14px; pointer-events: none; z-index: 100;
|
|
text-shadow: 0 0 10px rgba(34,211,238,0.8);
|
|
}
|
|
.info h1 { font-size: 20px; margin-bottom: 8px; }
|
|
.info p { opacity: 0.8; font-size: 12px; margin: 4px 0; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="canvas-container"></div>
|
|
<div class="info">
|
|
<h1>14 - VORTEX</h1>
|
|
<p>龙卷风 - 螺旋上升气流</p>
|
|
<p>粒子数: <span id="count">0</span></p>
|
|
<p>FPS: <span id="fps">0</span></p>
|
|
</div>
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/postprocessing/EffectComposer.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/postprocessing/RenderPass.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/postprocessing/ShaderPass.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/shaders/CopyShader.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/shaders/LuminosityHighPassShader.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/postprocessing/UnrealBloomPass.js"></script>
|
|
|
|
<script>
|
|
const COUNT = 8000;
|
|
const BANDS = 5; // 5层风带
|
|
|
|
const scene = new THREE.Scene();
|
|
scene.fog = new THREE.FogExp2(0x000000, 0.004);
|
|
const camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 2000);
|
|
camera.position.set(40, 30, 60);
|
|
|
|
const renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: "high-performance" });
|
|
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
|
|
document.getElementById('canvas-container').appendChild(renderer.domElement);
|
|
|
|
const controls = new THREE.OrbitControls(camera, renderer.domElement);
|
|
controls.enableDamping = true;
|
|
controls.autoRotate = true;
|
|
controls.autoRotateSpeed = 0.5;
|
|
|
|
const renderScene = new THREE.RenderPass(scene, camera);
|
|
const bloomPass = new THREE.UnrealBloomPass(new THREE.Vector2(window.innerWidth, window.innerHeight), 1.5, 0.4, 0);
|
|
bloomPass.strength = 1.5; bloomPass.radius = 0.4; bloomPass.threshold = 0;
|
|
const composer = new THREE.EffectComposer(renderer);
|
|
composer.addPass(renderScene);
|
|
composer.addPass(bloomPass);
|
|
|
|
const dummy = new THREE.Object3D();
|
|
const color = new THREE.Color();
|
|
const geometry = new THREE.BoxGeometry(0.3, 0.3, 0.3);
|
|
const material = new THREE.MeshBasicMaterial({ color: 0xffffff });
|
|
const instancedMesh = new THREE.InstancedMesh(geometry, material, COUNT);
|
|
instancedMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
|
|
scene.add(instancedMesh);
|
|
|
|
// 龙卷风粒子
|
|
const particles = [];
|
|
for (let i = 0; i < COUNT; i++) {
|
|
const band = Math.floor(Math.random() * BANDS);
|
|
const bandRadius = 3 + band * 4; // 每层半径递增
|
|
|
|
particles.push({
|
|
angle: Math.random() * Math.PI * 2,
|
|
height: Math.random() * 80 - 40,
|
|
radius: bandRadius + (Math.random() - 0.5) * 3,
|
|
band: band,
|
|
speed: 0.02 + (BANDS - band) * 0.005, // 内圈更快
|
|
upSpeed: 0.1 + Math.random() * 0.1,
|
|
wobble: Math.random() * Math.PI * 2,
|
|
size: 0.5 + Math.random() * 0.5
|
|
});
|
|
}
|
|
|
|
document.getElementById('count').textContent = COUNT;
|
|
let lastTime = performance.now(), frameCount = 0;
|
|
const fpsEl = document.getElementById('fps');
|
|
const clock = new THREE.Clock();
|
|
|
|
function animate() {
|
|
requestAnimationFrame(animate);
|
|
const now = performance.now();
|
|
frameCount++;
|
|
if (now - lastTime >= 1000) { fpsEl.textContent = frameCount; frameCount = 0; lastTime = now; }
|
|
|
|
const time = clock.getElapsedTime();
|
|
|
|
for (let i = 0; i < COUNT; i++) {
|
|
const p = particles[i];
|
|
|
|
// 旋转
|
|
p.angle += p.speed;
|
|
|
|
// 上升
|
|
p.height += p.upSpeed;
|
|
|
|
// 半径变化:越往上越细(漏斗形状)
|
|
const heightFactor = Math.max(0.1, 1 - (p.height + 40) / 100);
|
|
const currentRadius = p.radius * Math.sqrt(heightFactor) + Math.sin(time * 3 + p.wobble) * 0.5;
|
|
|
|
// 重置到底部
|
|
if (p.height > 40) {
|
|
p.height = -40;
|
|
p.angle = Math.random() * Math.PI * 2;
|
|
}
|
|
|
|
// 位置
|
|
const x = Math.cos(p.angle) * currentRadius;
|
|
const z = Math.sin(p.angle) * currentRadius;
|
|
const y = p.height;
|
|
|
|
dummy.position.set(x, y, z);
|
|
|
|
// 朝向旋转方向
|
|
dummy.rotation.y = -p.angle;
|
|
dummy.rotation.z = Math.atan2(p.upSpeed, p.speed * currentRadius) * 2;
|
|
|
|
// 大小:内圈更大更明显
|
|
const sizeScale = (BANDS - p.band + 1) / BANDS;
|
|
dummy.scale.setScalar(p.size * sizeScale * (1 + Math.sin(time * 5 + i * 0.01) * 0.3));
|
|
|
|
dummy.updateMatrix();
|
|
instancedMesh.setMatrixAt(i, dummy.matrix);
|
|
|
|
// 颜色:基于高度和层级
|
|
// 底部:深色,顶部:浅色
|
|
const heightRatio = (p.height + 40) / 80;
|
|
const hue = 0.5 + p.band * 0.02; // 青色到蓝色
|
|
const sat = 0.7 + heightRatio * 0.3;
|
|
const light = 0.2 + heightRatio * 0.5;
|
|
color.setHSL(hue, sat, light);
|
|
instancedMesh.setColorAt(i, color);
|
|
}
|
|
|
|
instancedMesh.instanceMatrix.needsUpdate = true;
|
|
instancedMesh.instanceColor.needsUpdate = true;
|
|
controls.update();
|
|
composer.render();
|
|
}
|
|
animate();
|
|
|
|
window.addEventListener('resize', () => {
|
|
camera.aspect = window.innerWidth / window.innerHeight;
|
|
camera.updateProjectionMatrix();
|
|
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
composer.setSize(window.innerWidth, window.innerHeight);
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|