c++李旭的爱心代码

时间: 2023-11-16 07:59:46 浏览: 46
``` <!DOCTYPE html> <html> <head> <title></title> </head> <style> * { padding: 0; margin: 0; } html, body { height: 100%; padding: 0; margin: 0; background: #000; } canvas { position: absolute; width: 100%; height: 100%; } .aa { position: fixed; left: 50%; bottom: 10px; color: #ccc; } </style> <body> <canvas id="pinkboard"></canvas> <script> /* * Settings */ var settings = { particles: { length: 500, // maximum amount of particles duration: 2, // particle duration in sec velocity: 100, // particle velocity in pixels/sec effect: -0.75, // play with this for a nice effect size: 30 // particle size in pixels } }; /* * RequestAnimationFrame polyfill by Erik M?ller */ (function () { var b = 0; var c = ["ms", "moz", "webkit", "o"]; for (var a = 0; a < c.length && !window.requestAnimationFrame; ++a) { window.requestAnimationFrame = window[c[a] + "RequestAnimationFrame"]; window.cancelAnimationFrame = window[c[a] + "CancelAnimationFrame"] || window[c[a] + "CancelRequestAnimationFrame"]; } if (!window.requestAnimationFrame) { window.requestAnimationFrame = function (h, e) { var d = new Date().getTime(); var f = Math.max(0, 16 - (d - b)); var g = window.setTimeout(function () { h(d + f); }, f); b = d + f; return g; }; } if (!window.cancelAnimationFrame) { window.cancelAnimationFrame = function (d) { clearTimeout(d); }; } })(); /* * Point class */ var Point = (function () { function Point(x, y) { this.x = typeof x !== "undefined" ? x : 0; this.y = typeof y !== "undefined" ? y : 0; } Point.prototype.clone = function () { return new Point(this.x, this.y); }; Point.prototype.length = function (length) { if (typeof length == "undefined") return Math.sqrt(this.x * this.x + this.y * this.y); this.normalize(); this.x *= length; this.y *= length; return this; }; Point.prototype.normalize = function () { var length = this.length(); this.x /= length; this.y /= length; return this; }; return Point; })(); /* * Particle class */ var Particle = (function () { function Particle() { this.position = new Point(); this.velocity = new Point(); this.acceleration = new Point(); this.age = 0; } Particle.prototype.initialize = function (x, y, dx, dy) { this.position.x = x; this.position.y = y; this.velocity.x = dx; this.velocity.y = dy; this.acceleration.x = dx * settings.particles.effect; this.acceleration.y = dy * settings.particles.effect; this.age = 0; }; Particle.prototype.update = function (deltaTime) { this.position.x += this.velocity.x * deltaTime; this.position.y += this.velocity.y * deltaTime; this.velocity.x += this.acceleration.x * deltaTime; this.velocity.y += this.acceleration.y * deltaTime; this.age += deltaTime; }; Particle.prototype.draw = function (context, image) { function ease(t) { return --t * t * t + 1; } var size = image.width * ease(this.age / settings.particles.duration); context.globalAlpha = 1 - this.age / settings.particles.duration; context.drawImage( image, this.position.x - size / 2, this.position.y - size / 2, size, size ); }; return Particle; })(); /* * ParticlePool class */ var ParticlePool = (function () { var particles, firstActive = 0, firstFree = 0, duration = settings.particles.duration; function ParticlePool(length) { // create and populate particle pool particles = new Array(length); for (var i = 0; i < particles.length; i++) particles[i] = new Particle(); } ParticlePool.prototype.add = function (x, y, dx, dy) { particles[firstFree].initialize(x, y, dx, dy); // handle circular queue firstFree++; if (firstFree == particles.length) firstFree = 0; if (firstActive == firstFree) firstActive++; if (firstActive == particles.length) firstActive = 0; }; ParticlePool.prototype.update = function (deltaTime) { var i; // update active particles if (firstActive < firstFree) { for (i = firstActive; i < firstFree; i++) particles[i].update(deltaTime); } if (firstFree < firstActive) { for (i = firstActive; i < particles.length; i++) particles[i].update(deltaTime); for (i = 0; i < firstFree; i++) particles[i].update(deltaTime); } // remove inactive particles while ( particles[firstActive].age >= duration && firstActive != firstFree ) { firstActive++; if (firstActive == particles.length) firstActive = 0; } }; ParticlePool.prototype.draw = function (context, image) { // draw active particles if (firstActive < firstFree) { for (i = firstActive; i < firstFree; i++) particles[i].draw(context, image); } if (firstFree < firstActive) { for (i = firstActive; i < particles.length; i++) particles[i].draw(context, image); for (i = 0; i < firstFree; i++) particles[i].draw(context, image); } }; return ParticlePool; })(); /* * Putting it all together */ (function (canvas) { var context = canvas.getContext("2d"), particles = new ParticlePool(settings.particles.length), particleRate = settings.particles.length / settings.particles.duration, // particles/sec time; // get point on heart with -PI <= t <= PI function pointOnHeart(t) { return new Point( 160 * Math.pow(Math.sin(t), 3), 130 * Math.cos(t) - 50 * Math.cos(2 * t) - 20 * Math.cos(3 * t) - 10 * Math.cos(4 * t) + 25 ); } // creating the particle image using a dummy canvas var image = (function () { var canvas = document.createElement("canvas"), context = canvas.getContext("2d"); canvas.width = settings.particles.size; canvas.height = settings.particles.size; // helper function to create the path function to(t) { var point = pointOnHeart(t); point.x = settings.particles.size / 2 + (point.x * settings.particles.size) / 350; point.y = settings.particles.size / 2 - (point.y * settings.particles.size) / 350; return point; } // create the path context.beginPath(); var t = -Math.PI; var point = to(t); context.moveTo(point.x, point.y); while (t < Math.PI) { t += 0.01; // baby steps! point = to(t); context.lineTo(point.x, point.y); } context.closePath(); // create the fill context.fillStyle = "#ea80b0"; context.fill(); // create the image var image = new Image(); image.src = canvas.toDataURL(); return image; })(); // render that thing! function render() { // next animation frame requestAnimationFrame(render); // update time var newTime = new Date().getTime() / 1000, deltaTime = newTime - (time || newTime); time = newTime; // clear canvas context.clearRect(0, 0, canvas.width, canvas.height); // create new particles var amount = particleRate * deltaTime; for (var i = 0; i < amount; i++) { var pos = pointOnHeart(Math.PI - 2 * Math.PI * Math.random()); var dir = pos.clone().length(settings.particles.velocity); particles.add( canvas.width / 2 + pos.x, canvas.height / 2 - pos.y, dir.x, -dir.y ); } // update and draw particles particles.update(deltaTime); particles.draw(context, image); } // handle (re-)sizing of the canvas function onResize() { canvas.width = canvas.clientWidth; canvas.height = canvas.clientHeight; } window.onresize = onResize; // delay rendering bootstrap setTimeout(function () { onResize(); render(); }, 10); })(document.getElementById("pinkboard")); </script> </body> </html> ``` ![示例图片](https://devbit-static.oss-cn-beijing.aliyuncs.com/devbit-static/img/heart.png)

相关推荐

最新推荐

recommend-type

销售指标完成对比图.xlsx

销售管理表,财务报表,占比分析,消费能力分析,日程安排,提成表,考核表 适用人群:学习不同技术领域的小白或进阶学习者;可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。
recommend-type

新客户开发分级标准(示例).xlsx

销售管理表,财务报表,占比分析,消费能力分析,日程安排,提成表,考核表 适用人群:学习不同技术领域的小白或进阶学习者;可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。
recommend-type

面向对象C++重要培训资料分享14面向对象C++开发技术资料.zip

面向对象C++重要培训资料分享14面向对象C++开发技术资料.zip
recommend-type

mmexport1722860388764.jpg

mmexport1722860388764.jpg
recommend-type

多商户免签个码免签支付微信支付宝QQ免签支付APP+PC监控码支付系统源码

个码免签支付 多商户免签 微信支付宝QQ免签支付 APP+PC监控 码支付系统源码 支付通道:支付宝、微信、QQ支付 支付宝需要挂APP监控或者PC监控,QQ支付执行设置访问URL任务即可实现回调 监控软件有PC版和2个APP监控,一个APP监控需要反编译修改下API,另一个手动配置即可使用 此免签码支付系统,兼容易支付接口,系统为多商户管理,商户额度控制 充值额度设置 订单时间设置 商户购买套餐设置 注册设置 域名设置(单独通道域名) 公告设置 商户通道管理等。 注:站长未测,转载过来说明已亲测,全网发布的都已测,太晚了站长未测了,后台密码的什么的也懒得去修改了,懂的自己处理,看了下后端是tp的,懂的就下载研究不明白的别问~~下载了也没用
recommend-type

右脑主导认知模式与课堂行为关联研究

本文是1984年《心理学在学校》(Psychology in the Schools)期刊第21卷的一篇学术论文,标题为《认知模式与课堂行为》。作者约翰·斯特尔纳、迈克·马洛韦和艾斯·科萨伊特来自怀俄明大学,他们针对小学生的认知模式与课堂行为之间的关系进行了深入研究。 研究方法涉及76名随机选取的小学生,他们接受了适应性儿童形式的“你的学习与思考方式”(SOLAT)评估,以获取他们的左脑、右脑和整合脑半球的认知模式分数。同时,教师对他们进行了行为评估,通过沃克问题行为识别清单(WPBIC)和非正式学习/行为问题清单来评价他们的课堂行为表现。 研究发现,那些被判定为主导右脑认知模式的学生(N=38)在学习/行为问题清单以及WPBIC的执行行为、退缩、分心和总评分上得分显著高于主导左脑认知模式(N=25)或整合脑半球认知模式(N=13)的学生。这表明右脑主导的认知模式可能与某些特定类型的课堂行为问题有关,如更倾向于行为表现(acting-out)、社交退缩(withdrawal)和注意力分散(distractibility)。 论文进一步探讨了认知模式得分与行为评估指标之间的相关性,揭示出右脑认知模式与这些行为问题存在较强的关联。这一研究成果对于理解个体差异在课堂行为中的作用具有重要意义,可能为教育实践者提供关于如何根据学生的认知优势调整教学策略和干预措施的启示。 这篇论文深入探讨了认知模式在小学生课堂行为中的潜在影响,强调了了解个体认知偏好对于优化教育环境和支持学生行为改进的重要性。通过量化分析和实证研究,它为教育心理学领域的理论和实践提供了有价值的数据支持。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

揭秘目标检测的秘密:OpenCV目标检测算法全解析,从Haar级联到YOLO

![揭秘目标检测的秘密:OpenCV目标检测算法全解析,从Haar级联到YOLO](https://www.mdpi.com/sensors/sensors-12-06447/article_deploy/html/images/sensors-12-06447f1.png) # 1. 目标检测概述** 目标检测是计算机视觉中一项重要的任务,它旨在从图像或视频中定位和识别感兴趣的对象。目标检测算法通常包括两个步骤: 1. **特征提取:**从图像中提取代表目标的特征,如形状、纹理和颜色。 2. **分类和定位:**将提取的特征分类为特定目标类别,并确定目标在图像中的位置。 # 2. 传统
recommend-type

mac系统安装Jupyter Notebook无法显示pyecharts可视化图表

当你在Mac系统上安装了Jupyter Notebook并试图运行含有Pyecharts的可视化代码时,可能会遇到显示图表的问题。这可能是由于几个原因: 1. **缺少依赖**:确保已经正确安装了Python、Jupyter、以及Pyecharts库。可以分别通过`pip install python` (对于Python基础环境)、`pip install jupyter notebook` 和 `pip install pyecharts` 安装。 2. **图形渲染设置**:Mac有时默认使用无图形界面的Tkinter作为图形库,这可能导致Pyecharts图表无法显示。你可以尝试安
recommend-type

教育领域的研究、发展与提升:应对质量挑战

"这篇论文探讨了教育领域中的研究、发展与改进问题,作者Richard E. Schutz指出,当前学校面临前所未有的挑战,学生数量的持续增长带来了新的质量性压力,这是美国教育的必要革命。教育改进可以依据实用性、效果可靠性、时间和成本等维度来衡量,并可以通过增强表现来实现。” 在教育领域,研究、开发与改进是至关重要的组成部分,特别是在面对不断扩大的学生群体和日益增长的教育需求时。Richard E. Schutz在其论文中引用了Francis Keppel的观点,强调了教育质量的提升已经成为当务之急。一个多世纪以来,学生数量的稳步增长带来了数量上的挑战,而如今,教育面临的新压力则是质量问题。这种对质量的关注被看作是美国教育的一场“必要革命”,意味着教育系统必须超越描述或解释现状,而需要实证展示教育的进步。 教育改进不再是一个抽象的概念,而是可以量化和衡量的。教育者不必将“改进”视为神秘的概念,而是可以借鉴其他领域评估改善的标准,如效用(utility)、效果的可靠性(reliability of effect)、时间效率(time)以及成本效益(cost)。通过这些指标,教育改进旨在提高教育的表现,确保教育服务对学生和社会更加有用,效果更加稳定,同时降低时间和经济成本。 在实践中,教育研究和开发有助于创新教学方法、课程设计和评估工具,以应对这些挑战。例如,利用技术进步可以提高教育的可访问性和个性化,大数据分析能够帮助教师更准确地理解学生的学习模式,进而调整教学策略。同时,对教育成果的持续评估和反馈机制的建立,有助于确保教育质量的持续改进。 此外,政策制定者和教育机构的角色在这一过程中至关重要。他们需要创建有利于创新的环境,支持教师的专业发展,投资于教育研究,并且建立有效的监测和评价体系,以确保改进措施的有效实施。教育改进不仅是教育内部的问题,它还涉及到社会、经济和文化等多个层面的互动,需要多方面的合作和努力。 "Research, Development, and Improvement in Education"这篇论文揭示了教育改进的紧迫性以及其实质性的内涵,强调了教育质量提升的多维度评估,为教育领域的未来发展方向提供了理论框架和实践指导。