1.在桌面新建文件夹

2.复制以下代码到文件夹

3.将文件夹后缀名改成html

<!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 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. notepad拼心形_bat心形代码

    本篇文章介绍了利用bat文件绘制心形的方法,感兴趣的小伙伴可以学习一下. bat心形代码 bat是Windows下的批处理文件类型,由一系列命令构成,其中可以包含对其他程序的调用.这个文件的每一行都是 ...

  2. 心形符号c语言程序,c语言心形代码及图形

    <c语言心形代码及图形>由会员分享,可在线阅读,更多相关<c语言心形代码及图形(3页珍藏版)>请在人人文库网上搜索. 1.include #include #include # ...

  3. c++心形编码_求一个C语言写成的心形代码?

    在你们的世界里,是不是觉得程序猿一点浪漫都不懂?其实不是的,程序猿的世界也是很浪漫滴...比如他们可以用代码实现心形,你们其他人可以吗?代码如下: 第一种: #include int main(){ ...

  4. C++ 和 EasyX绘制心形代码

    环境准备 Visual Studio 2019 Community(或任意VC10以上) 这里给出的Visual Studio链接是2022的,可以在页面最下端找到较早的下载项选项.详细的安装过程请移 ...

  5. python代码大全心形盒子简单_python心形代码

    广告关闭 腾讯云11.11云上盛惠 ,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高返5000元! 之前看到python一行代码就可以在控制台打印心形,感觉非常神奇,昨天突然想起来 ...

  6. c++心形代码_c语言心形告白代码实现

    c语言心形告白代码实现 1.彩色告白 include include include include define U 0.1 define V 0.053 void SetColor(unsigne ...

  7. python动态心形代码_父亲节,程序员几条代码硬核示爱

    祝所有的父亲,节日快乐! 父亲节要送什么? 对老爸的爱在心口难开怎么办? 都说父爱如山,山也需要偶尔的温情问候,与其在网上遍寻各种攻略,不如敲起手中的键盘,码出几行代码,用你最熟悉的方式表达对父亲的爱 ...

  8. java心形代码_使用java打印心型、圆形图案的实现代码_java

    相信对于打印三角形都没什么难度,只需要利用for循环嵌套使用就行 但是对于打印圆形和三角形不同因为到圆心距离相等的点一般不会横坐标和纵坐标都为整数 打印爱心 爱心的公式 (x²+y²-1)³-x²*y ...

  9. MATLAB心形代码

    心形一 n=200 x=linspace(-3,3,n) y=linspace(-3,3,n) z=linspace(-3,3,n) [X,Y,Z]=ndgrid(x,y,z) F=((-(X.^2) ...

最新文章

  1. linux 后台运行jar包命令,Linux 运行jar包命令(Cent OS 7后台运行jar包)
  2. spring mvc 接收页面表单List
  3. 用友Cell组件使用总结
  4. Python学习---Django路由系统【all】
  5. java 测量程序运行时间
  6. 开源 免费 java CMS - FreeCMS1.9 移动APP管理 执行配置
  7. http响应状态码列表
  8. java构建内存池队列_池化技术(线程池、连接池、内存池等)
  9. Linux拓展通配符的使用
  10. PDF 补丁丁 0.6.0.3369 版发布(修复保存文件时文件名替代符失效的问题)
  11. comsol积分函数_如何在 COMSOL 软件中合并解
  12. 机器学习算法总结之XGBoost(上)理论基础
  13. python excel插件_django使用插件下载excel的方法
  14. selenium无法调用chrome或者firefox的原因
  15. 剑指offer面试题55 - II. 平衡二叉树(后序遍历)(剪枝)
  16. b+tree索引在MyIsam和InnoDB的不同实现方式
  17. AndroidLinux gdb用法
  18. 无法回避的现实问题:“亲对象”也要明算账?
  19. 基于GoLang的MMO游戏服务器(四)
  20. linux samba yum,CentOS7下yum安装SAMBA全命令过程

热门文章

  1. 提取FBX文件中mesh的信息
  2. HTML5:爱奇艺首页图片轮播效果
  3. LiveNVR监控摄像头Onvif/RTSP接入流媒体平台如何配置默认用户账户及用户密码
  4. eclipse的中文版本安装方法
  5. 最基础且详细的 RPCA-ALM 算法推导过程(手写稿)
  6. 爬虫-大众点评评论信息(思路)
  7. Qt 关于去除虚线框的三种方法
  8. 初中生直升高中定下来了?预计2023年全面落实?教育部的回应来了
  9. 【Windows7库功能使用技巧 】
  10. 2019/4/2更新 重制3617-6.17 增加918+6.21 二合一引导启动系统盘