当前位置: 首页 > news >正文

用html实现数字生命

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>数学粒子动画</title><style>body {margin: 0;padding: 0;background-color: #000;display: flex;justify-content: center;align-items: center;height: 100vh;overflow: hidden;font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;}.container {position: relative;width: 100%;max-width: 900px;text-align: center;}canvas {background-color: black;border-radius: 8px;box-shadow: 0 0 20px rgba(0, 100, 255, 0.3);}.title {color: rgba(255, 255, 255, 0.85);margin-bottom: 20px;font-size: 2.2rem;text-shadow: 0 0 10px rgba(0, 150, 255, 0.8);letter-spacing: 1.5px;}.description {color: rgba(200, 220, 255, 0.7);max-width: 600px;margin: 20px auto;font-size: 1.1rem;line-height: 1.6;}.controls {margin: 20px 0;}.control-btn {background: rgba(30, 60, 120, 0.7);color: white;border: none;padding: 10px 20px;margin: 0 10px;border-radius: 4px;cursor: pointer;font-size: 1rem;transition: all 0.3s ease;outline: none;}.control-btn:hover {background: rgba(50, 100, 200, 0.9);transform: translateY(-2px);box-shadow: 0 5px 15px rgba(0, 100, 255, 0.4);}.footer {color: rgba(150, 180, 220, 0.6);margin-top: 25px;font-size: 0.9rem;}</style>
</head>
<body><div class="container"><h1 class="title">数学粒子动画</h1><canvas id="particleCanvas" width="900" height="900"></canvas><div class="description">这个动画展示了10,000个粒子按照复杂的数学公式运动。每个粒子的位置由三角函数的组合计算得出,创造出令人着迷的视觉效果。</div><div class="controls"><button id="pauseBtn" class="control-btn">暂停</button><button id="resetBtn" class="control-btn">重置</button><button id="speedUpBtn" class="control-btn">加速</button><button id="slowDownBtn" class="control-btn">减速</button></div><div class="footer">HTML5 Canvas实现 | 数学公式驱动的艺术</div></div><script>// 获取Canvas元素和上下文const canvas = document.getElementById('particleCanvas');const ctx = canvas.getContext('2d');// 粒子数组const particles = [];const numParticles = 10000;// 时间变量和速度控制let t = 0;let animationSpeed = 1;let isPaused = false;// 初始化粒子function initParticles() {particles.length = 0;for (let i = 0; i <= numParticles; i++) {const x = i % 200;const y = i / 43;const k = 5 * Math.cos(x / 14) * Math.cos(y / 30);const e = y / 8 - 13;const d = (k * k + e * e) / 59 + 4;const a = Math.atan2(k, e);particles.push({k, e, d, a,x: 0, // 将在更新时计算y: 0  // 将在更新时计算});}}// 更新粒子位置function updateParticles() {t += Math.PI / 20 * animationSpeed;for (let i = 0; i < particles.length; i++) {const p = particles[i];const q = 60 - 3 * Math.sin(p.a * p.e) + p.k * (3 + 4 / p.d * Math.sin(p.d * p.d - t * 2));const c = p.d / 2 + p.e / 99 - t / 18;p.x = q * Math.sin(c) + 200;p.y = (q + p.d * 9) * Math.cos(c) + 200;}}// 绘制粒子function drawParticles() {ctx.fillStyle = 'rgba(0, 0, 0, 0.15)';ctx.fillRect(0, 0, canvas.width, canvas.height);for (let i = 0; i < particles.length; i++) {const p = particles[i];// 根据位置计算颜色const colorValue = Math.floor(150 + 100 * Math.sin(t/5 + p.x/50));ctx.fillStyle = `rgba(150, ${colorValue}, 255, 0.4)`;ctx.beginPath();ctx.arc(p.x, p.y, 1.2, 0, Math.PI * 2);ctx.fill();}}// 动画循环function animate() {if (!isPaused) {updateParticles();drawParticles();}requestAnimationFrame(animate);}// 事件监听器document.getElementById('pauseBtn').addEventListener('click', function() {isPaused = !isPaused;this.textContent = isPaused ? '继续' : '暂停';});document.getElementById('resetBtn').addEventListener('click', function() {t = 0;animationSpeed = 1;initParticles();});document.getElementById('speedUpBtn').addEventListener('click', function() {animationSpeed = Math.min(animationSpeed + 0.5, 5);});document.getElementById('slowDownBtn').addEventListener('click', function() {animationSpeed = Math.max(animationSpeed - 0.5, 0.5);});// 初始化并开始动画initParticles();animate();</script>
</body>
</html>
http://www.lqws.cn/news/488215.html

相关文章:

  • 日志技术-Logback入门程序
  • Life:Internship in OnSea Day 1
  • 【nvidia-H100-ib排障实战2】:服务器 InfiniBand 网络性能问题深度分析
  • 深入理解JavaScript设计模式之迭代器模式
  • 【python实用小脚本-111】基于PyTorch的人脸口罩检测系统技术文档
  • 构建你的API防护盾 - 抵御恶意爬虫、注入与业务欺诈
  • qwen 的词编码模型中tokenid 到 高维向量是什么实现的,tokenid的排列有什么特点
  • 【Altium Designer】---- 02创建元器件符号和封装
  • 基本图算法介绍
  • Maven 之 JUnit 测试体系构建全解析
  • 淘宝直播带货API开发:弹幕抓取与商品点击热力图生成系统
  • 春秋云镜【CVE-2017-18349】fastjson wp
  • 从java到vue3:第一天
  • 支持向量机(SVM):数学引擎与工程实践深度解析——从最大间隔到核技巧的完整推导与应用
  • 【技术分享】XR技术体系浅析:VR、AR与MR的区别、联系与应用实践
  • 从 0 到 1 构建 Graph RAG 系统:本地图谱 + 通义千问落地实践
  • 【DeepSeek实战】2、DeepSeek特训:Function Calling与ReAct双引擎驱动大模型智能升级实战指南
  • Redis04
  • Solidity 入门教程(三):函数 Function 详解 —— 用对函数,写好合约
  • npm ci对比npm install
  • 榕壹云无人售货机管理系统:开源架构赋能私有化部署,打造智能零售技术解决方案
  • Angular进阶之十二:Chrome DevTools+Angular实战诊断指南
  • mfc与vs成功在xp系统所需做的修改
  • leetcode83.删除排序链表中的重复元素
  • mongoDB服务本地化部署
  • 利用栈,实现括号匹配功能
  • OVS Faucet练习(下)
  • 百胜软件胜券AI:打造智慧零售运营新范式
  • 预训练语言模型基础知识概述
  • 使用Vue重新构建应用程序