c++爱心代码祝福好朋友

时间: 2023-11-19 14:55:46 浏览: 106
``` <!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

win10环境下vscode Linux C++开发代码自动提示配置(基于WSL)

主要介绍了win10环境下vscode Linux C++开发代码自动提示配置(基于WSL),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
recommend-type

学籍管理系统源代码 c++.docx

为了学校更加高效,快捷,方便的管理学生信息,并实现以下功能: (1)对学生信息进行录入:先输入学生的学籍,然后输入学生姓名,年龄,性别,籍贯,系别,专业,班级等,最后输入学生状态(入学)。...
recommend-type

使用C++调用Python代码的方法详解

主要介绍了使用C++调用Python代码并给大家介绍了.py和.pyc的区别,本文给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
recommend-type

约瑟夫环问题用C++代码实现

8. 【题目】约瑟夫环(约瑟夫问题)是一个数学的应用问题:已知n个人(以编号1,2,3...n分别表示)围坐在一张圆桌周围。从编号为1的人开始报数,数到k的那个人出列;他的下一个人又从1开始报数,数到k的那个人又...
recommend-type

c++读取excel的代码详解

c++如何读取excel?C++ ODBC操作excel全过程 想要通过ODBC直接读、写Excel表格文件,首先,应确保ODBC中已安装有Excel表格文件的驱动”MICROSOFT EXCEL DRIVER (*.XLS)”。然后,可根据下面步骤进行: 1. 在StdAfx.h...
recommend-type

藏经阁-应用多活技术白皮书-40.pdf

本资源是一份关于“应用多活技术”的专业白皮书,深入探讨了在云计算环境下,企业如何应对灾难恢复和容灾需求。它首先阐述了在数字化转型过程中,容灾已成为企业上云和使用云服务的基本要求,以保障业务连续性和数据安全性。随着云计算的普及,灾备容灾虽然曾经是关键策略,但其主要依赖于数据级别的备份和恢复,存在数据延迟恢复、高成本以及扩展性受限等问题。 应用多活(Application High Availability,简称AH)作为一种以应用为中心的云原生容灾架构,被提出以克服传统灾备的局限。它强调的是业务逻辑层面的冗余和一致性,能在面对各种故障时提供快速切换,确保服务不间断。白皮书中详细介绍了应用多活的概念,包括其优势,如提高业务连续性、降低风险、减少停机时间等。 阿里巴巴作为全球领先的科技公司,分享了其在应用多活技术上的实践历程,从早期集团阶段到云化阶段的演进,展示了企业在实际操作中的策略和经验。白皮书还涵盖了不同场景下的应用多活架构,如同城、异地以及混合云环境,深入剖析了相关的技术实现、设计标准和解决方案。 技术分析部分,详细解析了应用多活所涉及的技术课题,如解决的技术问题、当前的研究状况,以及如何设计满足高可用性的系统。此外,从应用层的接入网关、微服务组件和消息组件,到数据层和云平台层面的技术原理,都进行了详尽的阐述。 管理策略方面,讨论了应用多活的投入产出比,如何平衡成本和收益,以及如何通过能力保鲜保持系统的高效运行。实践案例部分列举了不同行业的成功应用案例,以便读者了解实际应用场景的效果。 最后,白皮书展望了未来趋势,如混合云多活的重要性、应用多活作为云原生容灾新标准的地位、分布式云和AIOps对多活的推动,以及在多云多核心架构中的应用。附录则提供了必要的名词术语解释,帮助读者更好地理解全文内容。 这份白皮书为企业提供了全面而深入的应用多活技术指南,对于任何寻求在云计算时代提升业务韧性的组织来说,都是宝贵的参考资源。
recommend-type

管理建模和仿真的文件

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

MATLAB矩阵方程求解与机器学习:在机器学习算法中的应用

![matlab求解矩阵方程](https://img-blog.csdnimg.cn/041ee8c2bfa4457c985aa94731668d73.png) # 1. MATLAB矩阵方程求解基础** MATLAB中矩阵方程求解是解决线性方程组和矩阵方程的关键技术。本文将介绍MATLAB矩阵方程求解的基础知识,包括矩阵方程的定义、求解方法和MATLAB中常用的求解函数。 矩阵方程一般形式为Ax=b,其中A为系数矩阵,x为未知数向量,b为常数向量。求解矩阵方程的过程就是求解x的值。MATLAB提供了多种求解矩阵方程的函数,如solve、inv和lu等。这些函数基于不同的算法,如LU分解
recommend-type

触发el-menu-item事件获取的event对象

触发`el-menu-item`事件时,会自动传入一个`event`对象作为参数,你可以通过该对象获取触发事件的具体信息,例如触发的元素、鼠标位置、键盘按键等。具体可以通过以下方式获取该对象的属性: 1. `event.target`:获取触发事件的目标元素,即`el-menu-item`元素本身。 2. `event.currentTarget`:获取绑定事件的元素,即包含`el-menu-item`元素的`el-menu`组件。 3. `event.key`:获取触发事件时按下的键盘按键。 4. `event.clientX`和`event.clientY`:获取触发事件时鼠标的横纵坐标
recommend-type

藏经阁-阿里云计算巢加速器:让优秀的软件生于云、长于云-90.pdf

阿里云计算巢加速器是阿里云在2022年8月飞天技术峰会上推出的一项重要举措,旨在支持和服务于企业服务领域的创新企业。通过这个平台,阿里云致力于构建一个开放的生态系统,帮助软件企业实现从云端诞生并持续成长,增强其竞争力。该加速器的核心价值在于提供1对1的技术专家支持,确保ISV(独立软件供应商)合作伙伴能获得与阿里云产品同等的技术能力,从而保障用户体验的一致性。此外,入选的ISV还将享有快速在钉钉和云市场上线的绿色通道,以及与行业客户和投资机构的对接机会,以加速业务发展。 活动期间,包括百奥利盟、极智嘉、EMQ、KodeRover、MemVerge等30家企业成为首批计算巢加速器成员,与阿里云、钉钉以及投资界专家共同探讨了技术进步、产品融合、战略规划和资本市场的关键议题。通过这次合作,企业可以借助阿里云的丰富资源和深厚技术实力,应对数字化转型中的挑战,比如精准医疗中的数据处理加速、物流智慧化的升级、数字孪生的普及和云原生图数据库的构建。 阿里云计算巢加速器不仅是一个技术支持平台,也是企业成长的催化剂。它通过举办类似2023年2月的集结活动,展示了如何通过云计算生态的力量,帮助企业在激烈的竞争中找到自己的定位,实现可持续发展。参与其中的优秀企业如神策和ONES等,都在这个平台上得到了加速和赋能,共同推动了企业服务领域的创新与进步。总结来说,阿里云计算巢加速器是一个集技术、资源和生态支持于一体的全方位服务平台,旨在帮助企业软件产业在云端绽放光彩。