<style>
#papa { --state: running; margin: 30px 0; left: calc(50% - 81px); transform: translateX(-50%); width: clamp(600px, 90vw, 1400px); height: auto; aspect-ratio: 16/9; background: url('https://638183.freep.cn/638183/t24/webp3/u1.webp') no-repeat center/cover; display: grid; place-items: center; box-shadow: 2px 2px 10px rgba(0,0,0,.65); z-index: 1; position: relative; }
#papa canvas { display: block; position: absolute; }
#player { position: absolute; top: 20%; width: 10%; cursor: pointer; opacity: 0.5; transition: width .75s; z-index: 9; animation: rot 10s linear infinite var(--state); }
#player:hover { opacity: .8; width: 12%; filter: drop-shadow(0 0 30px yellow); }
#btnFs { bottom: 20px; color: lightblue; border-color: lightblue !important; background: gray; }
#btnFs:hover { color: gold; }
@keyframes rot { to { transform: rotate(1turn); } }
</style>
<div id="papa">
<audio id="aud" src="https://music.163.com/song/media/outer/url?id=2616432338" autoplay loop></audio>
<img id="player" src="https://638183.freep.cn/638183/small/002_133507167677724892.png" alt="" />
</div>
<!--script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script-->
<script type="module">
import * as THREE from 'https://esm.sh/three';
import { FS } from 'https://638183.freep.cn/638183/web/ku/fscreen.js';
FS(papa, player);
function createParticles(options = {}) {
var isPaused = false;
const config = {
count: options.count || 3000,
size: options.size || 0.2,
colors: options.colors || ['purple', 'cyan', 'orange'],
speedRange: options.speedRange || [0.5, 0.8]
};
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, papa.offsetWidth/papa.offsetHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setSize(papa.offsetWidth, papa.offsetHeight);
renderer.setClearAlpha(0);
papa.appendChild(renderer.domElement);
const geometry = new THREE.BufferGeometry();
const positions = new Float32Array(config.count * 3);
const velocities = new Float32Array(config.count);
const colors = new Float32Array(config.count * 3);
for (var i = 0; i < config.count; i++) {
positions[i*3] = (Math.random() - 0.5) * 50;
positions[i*3+1] = (Math.random() - 0.5) * 50;
positions[i*3+2] = -50 + Math.random() * 150;
velocities[i] = config.speedRange[0] + Math.random() * (config.speedRange[1] - config.speedRange[0]);
const color = new THREE.Color(
config.colors.length > 1 ?
config.colors[Math.floor(Math.random()*config.colors.length)] :
'#'+(Math.random()*0xFFFFFF<<0).toString(16)
);
colors[i*3] = color.r;
colors[i*3+1] = color.g;
colors[i*3+2] = color.b;
}
geometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
geometry.setAttribute('velocity', new THREE.BufferAttribute(velocities, 1));
geometry.setAttribute('color', new THREE.BufferAttribute(colors, 3));
const material = new THREE.PointsMaterial({
size: config.size,
vertexColors: THREE.VertexColors || true,
transparent: true,
opacity: 0.8,
blending: THREE.AdditiveBlending
});
const particles = new THREE.Points(geometry, material);
scene.add(particles);
camera.position.z = 50;
const clock = new THREE.Clock();
function animate() {
if (isPaused) return;
const delta = clock.getDelta();
const positions = particles.geometry.attributes.position.array;
const velocities = particles.geometry.attributes.velocity.array;
for (var i = 0; i < config.count; i++) {
const zIdx = i * 3 + 2;
positions[zIdx] += velocities[i] * delta * 60;
if (positions[zIdx] > 100) {
positions[zIdx-2] = (Math.random() - 0.5) * 50;
positions[zIdx-1] = (Math.random() - 0.5) * 50;
positions[zIdx] = -50 - Math.random() * 50;
}
}
particles.geometry.attributes.position.needsUpdate = true;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
window.addEventListener('resize', () => {
renderer.setSize(papa.offsetWidth, papa.offsetHeight);
});
document.addEventListener('click', () => {
isPaused = aud.paused;
animate();
});
}
createParticles({
count: 3000,
colors: ['red', 'blue', 'green', 'yellow'],
speedRange: [0.02, 0.2]
});
</script>
|