【写在开头】

不知道发生什么事了?点我
看到最近《点燃我温暖你》中男主角——理工男李峋的爱心代码撩到了无数人,于是把代码开源分享给大家。
哈哈哈,只是长的比较像,李峋的爱心代码你得找李峋去要了

【具体效果】
如下:

【实现代码】

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>canvas 心</title><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>

【修改】

看到其他平台还有跳动的,我不允许你不会

简单还是原来的代码,只不过要修改style

修改部分代码如下:

<style>
html,
body {height: 100%;padding: 0;margin: 0;background: #000;display: flex;justify-content: center;align-items: center;
}@keyframes scaleDraw {/*定义关键帧、scaleDrew是需要绑定到选择器的关键帧名称*/0% {transform: scale(1);/*开始为原始大小*/}25% {transform: scale(1.3);/*放大1.1倍*/}50% {transform: scale(1);}75% {transform: scale(1.3);}
}canvas {position: absolute;width: 50%;height: 50%;-webkit-animation-name: scaleDraw;/*关键帧名称*/-webkit-animation-timing-function: ease-in-out;/*动画的速度曲线*/-webkit-animation-iteration-count: infinite;/*动画播放的次数*/-webkit-animation-duration: 3s;/*动画所花费的时间*/
}
</style>

【读者反馈】
看了评论,有人人不知道怎么用这个代码实现效果
我来写一下

1.首先在你的桌面新建 index.txt文件
2. 然后打开这个新建的文件,粘贴我的代码-保存
3.最后修改文件后缀为.html (这个地方一定要是 .html 后缀) 然后双击打开即可。。

完结,撒花~

【html】理工男李峋的极致浪漫:爱心代码|和你的心跳同频共振相关推荐

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

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

  2. 用Python制作会跳动的心,体验理工男李峋的浪漫

    前言 最近有个剧挺火的 就是那个程序员的剧,叫什么温暖你来着 咳咳,剧情我没怎么看,但是吧,里面有个爱心代码,最近可是蛮火的,今天就用Python来尝试一下吧 搞这个表白也是不错滴,之前还写了篇 也不 ...

  3. HTML爱心代码 | 《点燃我温暖你》中男主角——理工男李峋同款

    运行示例:  完整代码: 不知道怎么运行的,或者想添加背景图片的往后看!!!! HTML代码如下: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4. ...

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

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

  5. 李峋同款爱心代码(附源码)

    李峋同款浪漫爱心代码(快拿去给爸爸妈妈,给男(女)朋友看!!!) 基于新建文件基础上.txt文档 <html> <head><meta charset="utf ...

  6. HTML爱心代码 | 一起体验理工男的极致浪漫(电视剧男主同款)

    写在前面 大家好,我是陈橘又青,今天中午刷微博,看到最近<点燃我温暖你>中男主角--理工男李峋的爱心代码撩到了无数人,于是把代码开源分享给大家. 文章目录 写在前面 运行示例 完整代码 保 ...

  7. HTML文本抖音李峋同款爱心代码超好看

    热播剧李峋的超炫爱心代码同款,让你现实中感受电视剧情节,拿去感受感受计算机天才的魅力吧~ 代码展示 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4. ...

  8. 理工男你要懂爱,女朋友不会从天上掉下来 | 钛空精分小剧场

    关注"潜在价值",最好的技术商业媒体,了解那些智慧商业 本文由潜在价值旗下 创意产品推荐平台"钛空舱"推出 钛空(ID:TiKong-life) 一个关注于科技 ...

  9. 华为新手机采用自由曲面镜头,理工男的浪漫or追求技术的极致

    文章来源:前瞻网,作者:Winnie Lee 近日华为发布了Mate 40 Pro+新机,通过详细参数可以看到,作为一款旗舰机型,Mate 40 Pro+采用的诸多新技术无疑是非常值得关注的,其中最值 ...

最新文章

  1. NCBI dbGap数据下载记录
  2. android videoview播放进度,android – 获取视频播放视频的进度时间?
  3. MC34063组成DC-DC电路
  4. 怎样在Redis通过StackExchange.Redis 存储集合类型List
  5. 浅谈UWB室内定位(二)
  6. 每天一道剑指offer-把数组排成最小的数
  7. 灰色关联分析_(案例)相关分析之灰色关联度
  8. 原码,补码,反码概念和计算方法详解
  9. 科技爱好者周刊:第 83 期
  10. directadmin php.ini 修改,DirectAdmin 更改服务器IP
  11. 湖北移动CM201-1-CH _S905L3B-UWE5621DS_线刷固件包
  12. discuz X程序目录和文件列表 详细中文说明
  13. Kotlin只是一个“网红,【面试必备】
  14. Linux的使用及软件安装
  15. 野田圣子、希尔顿、松下幸之助,都喝过马桶水吗? .
  16. 三角测量(triangulation)
  17. 学习总结-ADC的基本概念
  18. 近期的热点风险事件都与这些内容相关
  19. 深入浅出Yolo系列之Yolov3Yolov4核心基础知识完整讲解
  20. 【输出N行杨辉三角形】两种输出方式(直角三角形型和等腰三角形型)C语言

热门文章

  1. 邮件发送时间怎么修改 python_使用python通过电子邮件发送日期时间
  2. 【工程师笔记】第六期:一项Xeon E5-2600 v4测试数据的背后
  3. 中科院计算机学院考研真题,2021年862计算机学科中国科学院大学考研真题及详解...
  4. 二叉树的层序遍历与镜像翻转js
  5. 绿竹生物上市破发:首日跌33% 募资2亿收盘市值45亿港元
  6. sapi/cgi/php-cgi,sapi/cgi/php-cgi
  7. 我的win10平板维修,重刷系统的经验,windows pe5.0拯救我的平板
  8. ue4 小知识点 图片变灰 hlsl 材质 custom shader
  9. bcdedit添加linux引导,用BCDEdit编辑启动菜单
  10. 利用mobi 和 epub 电子书文件建立自己的书库