151 lines
6.8 KiB
HTML
151 lines
6.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>07 - S7777 | 数字7777</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: #ff0066;
|
|
font-size: 14px; pointer-events: none; z-index: 100;
|
|
text-shadow: 0 0 10px rgba(255,0,102,0.5);
|
|
}
|
|
.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>07 - S7777</h1>
|
|
<p>数字 7777 粒子艺术</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 = 10000;
|
|
const scene = new THREE.Scene();
|
|
scene.fog = new THREE.FogExp2(0x000000, 0.008);
|
|
const camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 2000);
|
|
camera.position.set(0, 0, 80);
|
|
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 = 1.0;
|
|
|
|
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.8; bloomPass.radius = 0.5; 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 target = new THREE.Vector3();
|
|
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 positions = [];
|
|
for (let i = 0; i < COUNT; i++) {
|
|
positions.push(new THREE.Vector3(0, 0, 0));
|
|
}
|
|
|
|
// 数字7的点阵定义
|
|
const sevenPoints = [];
|
|
const addDigit = (offsetX) => {
|
|
// 7的上横
|
|
for (let x = 0; x < 6; x++) sevenPoints.push({x: offsetX + x, y: 8});
|
|
// 7的斜线
|
|
for (let y = 0; y < 9; y++) sevenPoints.push({x: offsetX + 5 - y*0.5, y: 8 - y});
|
|
};
|
|
// 四个7
|
|
addDigit(-20);
|
|
addDigit(-8);
|
|
addDigit(4);
|
|
addDigit(16);
|
|
|
|
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 digitIndex = Math.floor(i / 2500);
|
|
const localI = i % 2500;
|
|
|
|
if (localI < sevenPoints.length) {
|
|
const pt = sevenPoints[localI];
|
|
// 添加深度和波动
|
|
const z = Math.sin(time * 3 + i * 0.01) * 5;
|
|
const waveX = Math.cos(time * 2 + i * 0.005) * 0.5;
|
|
const waveY = Math.sin(time * 2 + i * 0.005) * 0.5;
|
|
target.set(pt.x + waveX, pt.y + waveY, z);
|
|
} else {
|
|
// 额外的粒子形成背景流动
|
|
const t = (i - sevenPoints.length) / (COUNT - sevenPoints.length * 4);
|
|
const angle = t * Math.PI * 2 * 4 + time;
|
|
const r = 30 + Math.sin(t * 10 + time) * 5;
|
|
target.set(Math.cos(angle) * r, Math.sin(angle) * r * 0.5, Math.sin(time + i * 0.01) * 10);
|
|
}
|
|
|
|
positions[i].lerp(target, 0.05);
|
|
dummy.position.copy(positions[i]);
|
|
dummy.rotation.set(time + i*0.001, time + i*0.002, 0);
|
|
dummy.updateMatrix();
|
|
instancedMesh.setMatrixAt(i, dummy.matrix);
|
|
|
|
// 颜色:数字部分亮红,背景暗红渐变
|
|
const isDigit = (i % 2500) < sevenPoints.length;
|
|
const hue = isDigit ? 0.95 : 0.0;
|
|
const lightness = isDigit ? 0.5 + Math.sin(time * 5 + i * 0.01) * 0.2 : 0.2;
|
|
color.setHSL(hue, 1.0, lightness);
|
|
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>
|