<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>反向粒子心形</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
background: #0a0a1a;
overflow: hidden;
}
.container {
position: relative;
width: 100vw;
height: 100vh;
}
/* 粒子系统 */
.particles {
position: absolute;
width: 100%;
height: 100%;
filter: drop-shadow(0 0 10px rgba(255,80,80,0.2));
}
.particle {
position: absolute;
border-radius: 50%;
pointer-events: none;
mix-blend-mode: screen;
transition: transform 0.8s ease-out;
}
/* 动画定义 */
@keyframes particle-flow {
0% { transform: translate(0,0); opacity: 0.8; }
50% { transform: translate(var(--tx), var(--ty)); opacity: 0.4; }
100% { transform: translate(0,0); opacity: 0.8; }
}
</style>
</head>
<body>
<div class="container">
<div class="particles"></div>
</div>
<script>
// 配置参数
const config = {
totalParticles: 3000, // 增加粒子数量
baseRadius: 300, // 基础半径
colorRange: ['#ff6666', '#ff9999', '#ffcccc']
};
// 心形极坐标方程
function heartShape(theta) {
return config.baseRadius * (1 - Math.sin(theta));
}
// 创建粒子系统
function createParticles() {
const container = document.querySelector('.particles');
for(let i = 0; i < config.totalParticles; i++) {
const particle = document.createElement('div');
particle.className = 'particle';
// 基础位置参数
const theta = Math.random() * Math.PI * 2;
const radius = heartShape(theta);
const baseX = radius * Math.cos(theta);
const baseY = radius * Math.sin(theta);
// 调整心形的方向
const adjustedX = baseX;
const adjustedY = -baseY;
// 动态参数
const size = 1 + Math.random() * 3;
const color = config.colorRange[Math.floor(Math.random()*3)];
const tx = (Math.random() - 0.5) * 80; // 增加运动幅度
const ty = (Math.random() - 0.5) * 80;
particle.style.cssText = `
width: ${size}px;
height: ${size}px;
background: ${color};
opacity: ${0.6 + Math.random()*0.3};
left: ${50 + adjustedX/1500*100}%;
top: ${50 + adjustedY/1500*100}%;
--tx: ${tx}px;
--ty: ${ty}px;
animation: particle-flow ${8 + Math.random()*4}s ease-in-out infinite;
animation-delay: ${Math.random()*5}s;
`;
container.appendChild(particle);
}
}
// 初始化
createParticles();
</script>
</body>
</html>