一、前言

电视剧《点燃我温暖你》中理工男李峋做的爱心代码非常好看,今天搬运来一个完整代码,快给你的那个她露一手吧~

二、代码实现

以下就是完整版的代码哦

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE> New Document </TITLE><META NAME="Generator" CONTENT="EditPlus"><META NAME="Author" CONTENT=""><META NAME="Keywords" CONTENT=""><META NAME="Description" CONTENT=""><style>html, body {height: 100%;padding: 0;margin: 0;background: #000;
}
canvas {position: absolute;width: 100%;height: 100%;
}</style></HEAD><BODY><canvas id="pinkboard"></canvas><script>/** Settings*/
var settings = {particles: {length:   500, // maximum amount of particlesduration:   2, // particle duration in secvelocity: 100, // particle velocity in pixels/seceffect: -0.75, // play with this for a nice effectsize:      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 poolparticles = 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 queuefirstFree++;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 particlesif (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 particleswhile (particles[firstActive].age >= duration && firstActive != firstFree) {firstActive++;if (firstActive == particles.length) firstActive = 0;}};ParticlePool.prototype.draw = function(context, image) {// draw active particlesif (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/sectime;// get point on heart with -PI <= t <= PIfunction 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 canvasvar 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 pathfunction 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 pathcontext.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 fillcontext.fillStyle = '#ea80b0';context.fill();// create the imagevar image = new Image();image.src = canvas.toDataURL();return image;})();// render that thing!function render() {// next animation framerequestAnimationFrame(render);// update timevar newTime   = new Date().getTime() / 1000,deltaTime = newTime - (time || newTime);time = newTime;// clear canvascontext.clearRect(0, 0, canvas.width, canvas.height);// create new particlesvar 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 particlesparticles.update(deltaTime);particles.draw(context, image);}// handle (re-)sizing of the canvasfunction onResize() {canvas.width  = canvas.clientWidth;canvas.height = canvas.clientHeight;}window.onresize = onResize;// delay rendering bootstrapsetTimeout(function() {onResize();render();}, 10);
})(document.getElementById('pinkboard'));</script></BODY>
</HTML>

三、运行效果

将代码复制到html页面中就可以实现了哦,快去试试吧

《点燃我温暖你》---爱心代码相关推荐

  1. 点燃我温暖你 爱心代码python

    大家最近有没有看点燃我,温暖你这部剧,陈飞宇扮演的天才编程少年李峋也太帅了吧,那我们就浅浅复刻一下低配版的爱心吧 效果展示如下 工具软件使用Pycharm运行 新建一个new file love.py ...

  2. 跳动的爱心代码,点燃我温暖你爱心代码

    如果能好好被爱,谁不想待在一个人身边一年有一年 创建一个文本,代码粘贴进去,后缀改为html,浏览器打开即可 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HT ...

  3. 低配版点燃我温暖你爱心代码

    图例 代码 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML>< ...

  4. 点燃你温暖我 爱心 源码

    复制到txt中,后缀改为html,双击运行就好啦,是动态的!!!!! <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional/ ...

  5. 《点燃我温暖你》中李峋的同款爱心代码

    前言 最近<点燃我温暖你>中李峋的爱心代码超级火,看着特别心动,这不,光棍节快到了,给兄弟们教学一波爱心代码,赶在双十一前表白,让这个双十一不在是孤单一个人! 目录 前言 Python简易 ...

  6. 214 情人节来袭,电视剧 《点燃我温暖你》李峋同款 Python爱心表白代码,赶紧拿去用吧

    大家好,我是徐公,六年大厂程序员经验,今天为大家带来的是动态心形代码,电视剧 <点燃我温暖你>同款的,大家赶紧看看,拿去向你心仪的对象表白吧,下面说一下灵感来源. 灵感来源 今天,早上起来 ...

  7. [Python]《点燃我,温暖你》李峋同款爱心代码

    代码原作者是[抖音:无所不能的法学生小黑] 代码原作者是[抖音:无所不能的法学生小黑] 代码原作者是[抖音:无所不能的法学生小黑] 重要的事情说三次 import random import sys ...

  8. 【Python】《点燃我,温暖你》,快来Get李峋同款爱心代码

    前言 hello,大家好 最近有个剧挺火的 就是那个程序员的剧,叫<点燃我,温暖你> 最近听说很火呀,那作为程序员,Python中的战斗机的小编,能不给大家安排一波! 怎么说呢,用这个表白 ...

  9. 李峋同款爱心代码 (超好看) | 电视剧《点燃我温暖你》

    李峋同款爱心代码 (超好看) | 电视剧<点燃我温暖你> 废话不多说,上代码: import random from math import sin, cos, pi, log from ...

最新文章

  1. java中用两个线程交替打印0-100偶数和奇数
  2. C#可扩展编程之MEF学习笔记(四):见证奇迹的时刻
  3. 2020-12-28 Matlab自动化控制-Adrc自抗扰控制
  4. Qt Creator指定动态属性
  5. caffe随记(八)---使用caffe训练FCN的pascalcontext-fcn32s模型(pascal-context数据集)
  6. 读书笔记7-浪潮之巅(part2)
  7. mysql怎么返回上一行_月球上并没有发射基地,阿波罗飞船是怎么返回地球的?...
  8. Linux运行级别介绍
  9. 学会这 6 招,网页搜索一秒就能搜到你想要的【老司机必备神技】
  10. isnan 函数 -javascript1.1
  11. React入门(暂缓)
  12. MATLAB for循环
  13. 最简单的Officescan快速卸载
  14. 小米路由器 charles无法抓包
  15. 输入年份 计算 生肖 C语言实现
  16. 阿卡索口语学习(Learn And Talk 0)短语及单词(二)
  17. \t转义字符占几个字节?
  18. android 捕获按键,Android捕获home和recent app按键
  19. maven添加阿里镜像急速提升jar下载速度
  20. java中遍历HashMap的方法

热门文章

  1. mtk android关机铃声,mtk android power key 长按8s 关机功能实现
  2. 推荐一个开源U盘启动工具——Ventoy
  3. 百度OCR文字识别教程(有demo)
  4. 鸿蒙系统能玩魔兽世界吗,魔兽世界:永久60级与TBC该怎么选,60级服务器真的会有玩家么?...
  5. input表单标签和label标签以及常使用标签的介绍
  6. python网络爬虫进入(一)——简单的博客爬行动物
  7. Centos8怎么关闭终端响铃? Centos系统取消终端响铃的方法
  8. 解决方案│POL全光校园解决方案 光纤到教室解决方案 光纤到宿舍解决方案
  9. git rebase -i_git rebase -i改变生活的魔力
  10. 获取对话框当前cfont_获取对话框当前cfont_MFC设置对话框、字体对话框、颜色对话框(转)...