HTML爱心代码 | 《点燃我温暖你》中男主角——理工男李峋同款
运行示例:
完整代码:
不知道怎么运行的,或者想添加背景图片的往后看!!!!
HTML代码如下:
<!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>
不是计算机专业的同学往下看 怎么运行!!
首先,在电脑桌面右击新建一个文本文档,并将上面给的代码复制粘贴进去,保存。
然后重命名这个文本文档,把后缀.txt改为.html格式
点击“是”即可,这时候这个文件就变成你浏览器的图标了,双击即可打开(也可以发给你喜欢的人,他可以直接在电脑上打开)
如果文件没有变成浏览器图标的话,右击这个文件,选择打开方式用你的浏览器打开即可。
看下效果:
后缀改了但是还是不行!原因如下:
部分朋友反应的修改了文件扩展名后没有弹出是否更改的选项,应该是你的电脑没有开启文件扩展名选项,大家打开“此电脑”后,点击查看——显示——勾选文件扩展名,然后再去修改即可!
添加背景图片:
在上面代码的第17行“position: absolute;”后添加下面这两行代码
background-image: url("love.jpg");background-size: contain;
然后在桌面把你想添加的背景图片命名为love.jpg即可!
效果图:
修改爱心颜色
1.找到你想要修改的颜色的 RGB色值(点击查询)
2.第215行代码“context.fillStyle = '#ea80b0'
;”中的 ea80b0
改成你想要颜色的色值即可。
HTML爱心代码 | 《点燃我温暖你》中男主角——理工男李峋同款相关推荐
- 【Python】《点燃我,温暖你》,快来Get李峋同款爱心代码
前言 hello,大家好 最近有个剧挺火的 就是那个程序员的剧,叫<点燃我,温暖你> 最近听说很火呀,那作为程序员,Python中的战斗机的小编,能不给大家安排一波! 怎么说呢,用这个表白 ...
- 李峋 爱心代码 点燃我温暖我
dy上很火的爱心代码如下:这里是用的vs code软件运行的 <!doctype html> <html> <head> <meta charset=&quo ...
- 李峋同款-C语言版本-爱心
近期很火的<点燃我,温暖你>很火,里面的李峋爱心代码相信很多人心动, 网上有很多的"李峋同款"爱心源码,但都不是C语言的,用语言描述一下,就是好多爱心,然后从内到外,从 ...
- 李峋同款会动的爱心Python代码版
最近看到不少关于李峋同款爱心的视频.文章,今天我们也分享一下李峋同款爱心 Python 代码版.要问李峋是谁?我也不太清楚,大家可自行百度,这个是我百度的结果,仅供参考. 简单来说李峋同款爱心就是一个 ...
- 214 情人节来袭,电视剧 《点燃我温暖你》李峋同款 Python爱心表白代码,赶紧拿去用吧
大家好,我是徐公,六年大厂程序员经验,今天为大家带来的是动态心形代码,电视剧 <点燃我温暖你>同款的,大家赶紧看看,拿去向你心仪的对象表白吧,下面说一下灵感来源. 灵感来源 今天,早上起来 ...
- 李峋同款爱心代码 (超好看) | 电视剧《点燃我温暖你》
李峋同款爱心代码 (超好看) | 电视剧<点燃我温暖你> 废话不多说,上代码: import random from math import sin, cos, pi, log from ...
- 李峋同款爱心代码-电视剧《点燃我温暖你》
浅浅模仿了一下李峋同款跳动的心,用python完成,引用了tkinter库,最后效果图如图1所示.电视剧里面应该是用AE做的动画(大概率是). """ @author:A ...
- 【Python】《点燃我,温暖你》李峋同款爱心_python程序
目录 前言 一.效果展示 二.设备准备 三.代码呈现 前言 偶然在抖音上刷到最近很火的电视剧<点燃我,温暖你>,看到很多人都在网上找源码,侥幸在b站上看见一位up主,简单地复刻了一下. 这 ...
- 李峋同款爱心代码(附源码,前端代码,python代码)
Hello 大家好 如何浪漫的表白,作为程序员出身的小编,今天就带你实现热播剧<点燃我,温暖你>中超火的李峋同款爱心代码!前面是教程,怕麻烦的朋友可以直接划到文末,下载现成的,下载完成后打 ...
最新文章
- 【Fragment】管理机制
- Google发布Anthos:Google背书,宣告多集群多云Kubernetes时代已来
- 使用CocoaPods出现 The `master` repo requires CocoaPods 0.32.1 - 问题解决
- hana::detail::variadic::foldl1用法的测试程序
- Mysql时间数据分段累加求和案例之子查询与SUM窗口函数
- python解压加密zip文件_Python:解压缩前检测一个zip文件否为加密,两种算法。
- ublox Android 定位超时,[RK3288] [Android 7.1] u-blox GPS调试
- 用计算机解决自动驾驶,自动驾驶汽车很美好,但这3个逻辑解决不了,依然是人类驾驶汽车...
- java oo原则_javaOO11-12:面向对象的设计原则、线程
- 【并行计算-CUDA开发】CUDA编程——GPU架构,由sp,sm,thread,block,grid,warp说起...
- mysql面试必会6题经典_经典sql面试题及答案第7期
- Linux驱动开发: USB驱动开发
- Java、JSP水费管理系统
- linux搜狗输入法16.04,Unbuntu16.04安装搜狗拼音输入法的图文教程
- 原型设计工具Axure
- 三星note3smn9005怎么放SIM卡
- 科技爱好者周刊(第 216 期):极简主义的胜利
- ecshop打开手机端QQ对话窗口
- MATLAB 三维立体绘图
- 在中断函数和MAIN函数中同时调用同一个函数的有趣现象