3d立体爱心粒子代码


以下是一个使用HTML5 Canvas和JavaScript创建的3D立体爱心粒子效果代码: ```html <!DOCTYPE html> <html> <head> <title>3D爱心粒子</title> <style> body { margin: 0; overflow: hidden; background: #000; } canvas { display: block; } </style> </head> <body> <canvas id="canvas"></canvas> <script> const canvas = document.getElementById('canvas'); const ctx = canvas.getContext('2d'); // 设置画布大小为窗口大小 canvas.width = window.innerWidth; canvas.height = window.innerHeight; // 粒子数组 const particles = []; const particleCount = 1500; // 爱心形状参数 const heartSize = Math.min(canvas.width, canvas.height) * 0.3; // 创建粒子 class Particle { constructor() { // 随机位置在爱心形状内 const angle = Math.random() * Math.PI * 2; const r = Math.random() * heartSize; const x = r * 16 * Math.pow(Math.sin(angle), 3); const y = -r * (13 * Math.cos(angle) - 5 * Math.cos(2*angle) - 2 * Math.cos(3*angle) - Math.cos(4*angle)); this.x = x + canvas.width / 2; this.y = y + canvas.height / 2; this.z = Math.random() * heartSize - heartSize/2; this.size = Math.random() * 2 + 1; this.color = `hsl(${Math.random() * 60 + 330}, 100%, 50%)`; this.speedX = Math.random() * 0.2 - 0.1; this.speedY = Math.random() * 0.2 - 0.1; this.speedZ = Math.random() * 0.2 - 0.1; } update() { // 3D效果 - 透视 const scale = 1 / (1 + this.z * 0.001); // 更新位置 this.x += this.speedX; this.y += this.speedY; this.z += this.speedZ; // 边界检查 if (this.z > heartSize/2 || this.z < -heartSize/2) { this.speedZ *= -1; } // 绘制粒子 ctx.fillStyle = this.color; ctx.beginPath(); ctx.arc( this.x, this.y, this.size * scale, 0, Math.PI * 2 ); ctx.fill(); } } // 初始化粒子 for (let i = 0; i < particleCount; i++) { particles.push(new Particle()); } // 动画循环 function animate() { ctx.fillStyle = 'rgba(0, 0, 0, 0.05)'; ctx.fillRect(0, 0, canvas.width, canvas.height); particles.forEach(particle => particle.update()); requestAnimationFrame(animate); } animate(); // 窗口大小调整 window.addEventListener('resize', () => { canvas.width = window.innerWidth; canvas.height = window.innerHeight; }); </script> </body> </html> ``` 代码说明: 1. 使用爱心参数方程创建3D爱心形状 2. 每个粒子在3D空间中有x,y,z坐标 3. 通过透视缩放实现3D效果 4. 粒子在爱心范围内随机运动 5. 使用HSL色彩空间实现多彩效果 注意事项: 1. 粒子数量(particleCount)可以根据设备性能调整 2. 爱心大小(heartSize)与窗口大小相关 3. 颜色范围(hsl)可以修改以获得不同色调效果 [2025-07-23 19:27:45 | AI写代码神器 | 885点数解答]
- c语言使用将整型变量a,b,c作为函数input的参数,用输入input输入这三个参数。再将a,b,c作为函数sort的参数。用sort将a,b,c将从大到小的顺序返回。并在主函数里面输出。 输入格式: "%d%d%d" 输出格式: "%3d%3d%3d\n" 输入样例: 1 2 3↙ 输出样例:(246点数解答 | 2024-10-22 22:06:20)189
- c语言使用将整型变量a,b,c作为函数input的参数,用输入input输入这三个参数。再将a,b,c作为函数sort的参数。用sort将a,b,c将从大到小的顺序返回。并在主函数里面输出。 输入格式: "%d%d%d" 输出格式: "%3d%3d%3d\n"(305点数解答 | 2024-10-22 22:07:27)251
- c语音 使用将整型变量a,b,c作为函数input的参数,用输入input输入这三个参数。再将a,b,c作为函数sort的参数。用sort将a,b,c将从大到小的顺序返回。并在主函数里面输出。 输入格式: "%d%d%d" 输出格式: "%3d%3d%3d\n" 输入样例: 1 2 3↙ 输出样例:(259点数解答 | 2024-10-25 00:53:10)135
- https://www.n.cn/?src=360ai_mso_aibox_online&s_type=l&q=%3C!doctype%20html%3E%20%3Chtml%20lang%3D%22zh-cn%22%3E%20%3Chead%3E%20%3Cmeta%20charset%3D%22utf-8%22%3E%20%3Cmeta%(92点数解答 | 2025-07-18 18:23:11)72
- 爱心(71点数解答 | 2025-03-01 16:58:36)172
- <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF - 8"> <meta name="viewport" content="width=device-width, initial - scale = 1.0"> <title>爱心</title> </head> <body> <canvas id="myCanvas" width="200" height="200"></canvas> <script> const canvas = document.getElementById('myCanvas'); const ctx = canvas.getContext('2d'); ctx.beginPath(); ctx.moveTo(100, 20); ctx.bezierCurveTo(140, 20, 160, 60, 100, 100); ctx.bezierCurveTo(165点数解答 | 2025-03-23 15:00:43)176
- <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>爱心</title> <style> .heart { width: 100px; height: 90px; position: relative; margin: 100px auto; } .heart:before, .heart:after { content: ""; position: absolute; top: 0; left: 0; width: 50px; height: 80px; background: red; border-radius: 50p(198点数解答 | 2025-05-01 13:24:06)115
- 以步进电动机闭环控制系统驱动的 3d 打印机项目目标 定位精度:达到 0.1 毫米级精度,实际定位误差不超过±0.05 毫米。 速度稳定性:在 0-50 毫米/秒的速度范围内,喷头移动速度波动不超过±5%。 响应及时性:对指令的响应时间不超过 50 毫秒,能在 100 毫秒内完成相应调整动作。 系统设计 1. 硬件选型 简要说明所选步进电动机型号和相关传感器等硬件。 2. 软件设计 (1)主程序流程图:[绘制主程序流程图] (2)各子程序流程图:[分别绘制各子程序流程图](3)代码,如何具体写(744点数解答 | 2024-07-03 15:18:13)230
- 利用指针编写一函数,输入3个整数,按由大到小的顺序将它们输出。 输入格式: %d 输出格式: %3d 输入样例: 25 68 17 输出样例: 68 25 17(564点数解答 | 2024-05-12 16:05:05)180
- error pulling image configuration: get https://production.cloudflare.docker.com/registry-v2/docker/registry/v2/blobs/sha256/dd/dde0cca083bc75a0af14262b1469b5141284b4399a62fef923ec0c0e3b21f5bc/data?verify=1718779567-yktk6tarop5zlci2foyzezv1d78%3d: dial tcp 162.125.18.133:443: i/o timeout 国内pull镜像超时(321点数解答 | 2024-06-19 13:59:41)245
- error pulling image configuration: get https://production.cloudflare.docker.com/registry-v2/docker/registry/v2/blobs/sha256/dd/dde0cca083bc75a0af14262b1469b5141284b4399a62fef923ec0c0e3b21f5bc/data?verify=1718779567-yktk6tarop5zlci2foyzezv1d78%3d: dial tcp 162.125.18.133:443: i/o timeout 国内pull镜像超时(174点数解答 | 2024-06-19 14:02:11)250
- ctr: failed to copy: httpreadseeker: failed open: failed to do request: get "https://production.cloudflare.docker.com/registry-v2/docker/registry/v2/blobs/sha256/e8/e8750203e98541223fb970b2b04058aae5ca11833a93b9f3df26bd835f66d223/data?verify=1718889407-z2%2fzuoq3stcmc3ffjbzyphxcaew%3d": dial tcp 210.56.51.192:443: i/o timeout(319点数解答 | 2024-06-20 20:28:30)530