feat: 优化 App.vue 和 ParticleBackground 组件的动画效果,调整粒子配置和运动参数,提升性能和视觉表现,同时增加节流控制以优化动画刷新率。
This commit is contained in:
@@ -12,21 +12,21 @@ const breakpoints = useBreakpoints({
|
||||
})
|
||||
|
||||
const isMobile = breakpoints.smaller('tablet')
|
||||
const particleCount = isMobile.value ? 1000 : 1800
|
||||
const particleCount = isMobile.value ? 800 : 1500
|
||||
|
||||
// 优化粒子配置
|
||||
const config = {
|
||||
particleSize: 2.5,
|
||||
systemRadius: 20,
|
||||
baseSpeed: 0.15,
|
||||
hoverRadius: 4,
|
||||
particleSize: isMobile.value ? 2.0 : 2.5,
|
||||
systemRadius: isMobile.value ? 15 : 20,
|
||||
baseSpeed: 0.1,
|
||||
hoverRadius: isMobile.value ? 3 : 4,
|
||||
color: 0xb4e0f7, // 主色调:浅蓝色
|
||||
colorVariation: [0xffb7d0, 0xa8d8ea, 0xf3e5f5], // 粒子颜色变化
|
||||
lineColor: 0xa8d8ea,
|
||||
lineDistance: 3.5,
|
||||
particleCount: isMobile.value ? 1200 : 2000,
|
||||
particleOpacity: 0.8,
|
||||
lineOpacity: 0.2,
|
||||
lineDistance: isMobile.value ? 2.5 : 3.5,
|
||||
particleCount: isMobile.value ? 800 : 1500,
|
||||
particleOpacity: 0.6,
|
||||
lineOpacity: 0.15,
|
||||
glowSize: 3
|
||||
}
|
||||
|
||||
@@ -193,37 +193,44 @@ const createConnections = (positions, colors) => {
|
||||
}
|
||||
|
||||
const animate = () => {
|
||||
requestAnimationFrame(animate)
|
||||
|
||||
const time = Date.now() * 0.0001
|
||||
particles.material.uniforms.time.value = time
|
||||
|
||||
if (!document.hidden) {
|
||||
requestAnimationFrame(animate)
|
||||
|
||||
const time = Date.now() * 0.00005
|
||||
particles.material.uniforms.time.value = time
|
||||
|
||||
if (time % 2 === 0) {
|
||||
updateParticles()
|
||||
}
|
||||
|
||||
renderer.render(scene, camera)
|
||||
}
|
||||
}
|
||||
|
||||
const updateParticles = () => {
|
||||
const positions = particles.geometry.attributes.position.array
|
||||
|
||||
for (let i = 0; i < config.particleCount; i++) {
|
||||
const i3 = i * 3
|
||||
|
||||
// 更自然的运动
|
||||
positions[i3] += Math.sin(time + i * 0.1) * 0.02
|
||||
positions[i3 + 1] += Math.cos(time + i * 0.05) * 0.02
|
||||
positions[i3 + 2] += Math.sin(time * 0.5 + i * 0.07) * 0.02
|
||||
positions[i3] += Math.sin(time + i * 0.05) * 0.01
|
||||
positions[i3 + 1] += Math.cos(time + i * 0.03) * 0.01
|
||||
positions[i3 + 2] += Math.sin(time * 0.3 + i * 0.04) * 0.01
|
||||
|
||||
// 鼠标交互优化
|
||||
if (mouse.x !== null && mouse.y !== null) {
|
||||
const dx = positions[i3] - mouse.x * 20
|
||||
const dy = positions[i3 + 1] - mouse.y * 20
|
||||
const distance = Math.sqrt(dx * dx + dy * dy)
|
||||
|
||||
if (distance < config.hoverRadius) {
|
||||
const force = (config.hoverRadius - distance) / config.hoverRadius
|
||||
positions[i3] += dx * force * 0.03
|
||||
positions[i3 + 1] += dy * force * 0.03
|
||||
const force = (config.hoverRadius - distance) / config.hoverRadius * 0.8
|
||||
positions[i3] += dx * force * 0.02
|
||||
positions[i3 + 1] += dy * force * 0.02
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
particles.geometry.attributes.position.needsUpdate = true
|
||||
renderer.render(scene, camera)
|
||||
}
|
||||
|
||||
const handleResize = () => {
|
||||
|
Reference in New Issue
Block a user