动态螺旋图形特效

<!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 {
            margin: 0;
            overflow: hidden;
            background-color: #000;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            flex-direction: column;
        }
        canvas {
            display: block;
        }
        .link {
            color: white;
            margin-top: 20px;
            font-family: Arial, sans-serif;
            text-decoration: none;
            transition: color 0.3s;
        }
        .link:hover {
            color: #00ffff;
        }
    </style>
</head>
<body>
    <canvas id="spiralCanvas"></canvas>

    <script>
        const canvas = document.getElementById('spiralCanvas');
        const ctx = canvas.getContext('2d');
        
        // 设置画布大小为窗口大小
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight - 60; // 为链接留出空间
        
        // 螺旋参数
        let angle = 0;
        const radius = 5;
        const spiralDensity = 0.1;
        const maxPoints = 1000;
        const points = [];
        
        // 颜色参数
        let hue = 0;
        
        function drawSpiral() {
            // 清除画布
            ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
            ctx.fillRect(0, 0, canvas.width, canvas.height);
            
            // 计算新点
            angle += 0.1;
            const distance = radius * angle;
            const x = canvas.width / 2 + Math.cos(angle) * distance * spiralDensity;
            const y = canvas.height / 2 + Math.sin(angle) * distance * spiralDensity;
            
            // 添加到点数组
            points.push({x, y});
            if (points.length > maxPoints) {
                points.shift();
            }
            
            // 绘制所有点
            for (let i = 0; i < points.length; i++) {
                const point = points[i];
                const size = i / points.length * 10;
                const alpha = i / points.length;
                
                // 颜色变化
                hue = (hue + 0.5) % 360;
                ctx.fillStyle = `hsla(${hue}, 100%, 50%, ${alpha})`;
                
                ctx.beginPath();
                ctx.arc(point.x, point.y, size, 0, Math.PI * 2);
                ctx.fill();
            }
            
            requestAnimationFrame(drawSpiral);
        }
        
        // 窗口大小改变时调整画布大小
        window.addEventListener('resize', () => {
            canvas.width = window.innerWidth;
            canvas.height = window.innerHeight - 60;
        });
        
        // 开始动画
        drawSpiral();
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值