跳动的心 — HTML 代码

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>跳动的心❤️</title><meta name="Generator" content="EditPlus"><meta name="Author" content="xiaoqi"><meta name="Keywords" , content="beating heart"><meta name="Description" content="canvas beating heart"><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: {// maximum amount of particleslength: 500,// particle duration in secduration: 2,// parrticle velicity in plxels/secvelocity: 100,// play with this for a nice effecteffect: -0.75,// particle size in pixelssize: 30,},};/** 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 iinactive 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),// particles/secparticleRate = settings.particles.length / settings.particles.duration,time;// get point on hert 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 thw 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) {// baby stepst += 0.01;point = to(t);context.lineTo(point.x, point.y);}context.closePath();// create the fillcontext.fillStyle = '#ea80b0';context.fill();// create th imagevar image = new Image();image.src = canvas.toDataURL();return image;})();// render that thingfunction 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. css实现跳动的心形图案

    前言: 使用伪元素来实现心效果,动画来实现跳动. 效果图: 实现代码: 1.template或者html定义一个容器 <div class="heart fr">< ...

  2. 使用css制作跳动的心

    利用css动画制作跳动的心 代码如下: <!DOCTYPE html> <html lang="en"><head><meta chars ...

  3. c语言编程16个点阵跳动的心,Arduino点阵制作跳动的心

    这次介绍的是使用8×8点阵(没有用到驱动模块,直接用Ardunio IO口控制)制作跳动的心.差不多用完所有IO口了,才能控制64个LED灯. 点阵说明 一般数码管有出厂信息:比如型号为LG5011A ...

  4. 用CSS3咋写“跳动的心”?

    CSS3写跳动的心需要哪些样式(属性)? 1.动画样式: 触发式动画:①触发条件: :hover :checked :active②动画的参数: transition-duration:5s;--时间 ...

  5. python绘制表情包笑脸_用micro:bit学Python ——阵列显示表情符号“笑脸跳动的心”...

    本节任务要求 使用Microbit LED阵列显示表情符号 "笑脸跳动的心" 题目分析 这是一个使用Python语言完成MicroBit板载LED阵列编程的入门进阶题目,属于入门阶 ...

  6. Css3 会跳动的心

    开发工具与关键技术:DW scale()缩放 撰写时间:2019年2月9日 先做一个简单的?图,再利用Css3的动画scale()函数让元素根据中心原点对对象进行缩放,这样就可以实现一颗会跳动的心了. ...

  7. HTML+CSS——实现跳动的心

    跳动的爱~心 所谓 爱心是指同情怜悯之心态(包括相应的一定行动) 它是一种奉献精神,更是关怀.爱护人的思想感情,包括于所有情感之中. 爱心的深层含义就是保护所有的动植物.广义的爱心就是保护所有生命 一 ...

  8. notepad拼心形_bat心形代码

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

  9. css 跳动的心_如何用纯CSS为您的情人打造一颗跳动的心

    css 跳动的心 Each year on February 14th, many people exchange cards, candies, gifts or flowers with thei ...

最新文章

  1. 【新拟态】左上角标签样式、ICON图标样式、模仿AppStore的应用图标
  2. 什么是最佳适应算法?
  3. UIEdgeInsets 说明
  4. 陈松松:视频营销成交率低,这三个因素没到位
  5. 测试过程中的防忽悠沟通法
  6. 经典MySQL语句大全和常用SQL语句命令的作用。
  7. angular项目打包发布流程
  8. AA.Dapper升级了
  9. 采集post传输的数据
  10. 全国信息技术水平计算机程序设计c,2010年(上)全国信息技术水平考试计算机程序设计技术水平证书(C语言)考试试卷...
  11. python 遍历字符串_python中如何实现遍历字符串的方法
  12. obs源码简析之推流
  13. autoucad2014激活就未响应_CAD2014激活错误怎么办,autocad2014激活错误的解决办法
  14. ffmpeg将视频转图片,图片转视频
  15. 用outlook登录163邮箱的超详细教程
  16. Android将2张图片合成一张图片(Bitmap类型)附二维码生成
  17. canvas图片合成
  18. [热键冲突]:Win10 输入法表情快捷键(Ctrl+Shift+B)如何关闭
  19. JAVA架构演变过程
  20. Python中以字母r/R,或字母u/U 开头的字符串

热门文章

  1. 微信公众号 Markdown 排版工具
  2. egg Cannot find module ‘diagnostics_channel‘
  3. MATHTYPE安装出现问题:无法打开要写入的文件;MathType打开word时“安全警告,宏已被禁用”;mathtype与AXmath不能同时使用
  4. android图片显示组件,Android可循环显示图像的Android Gallery组件用法实例
  5. 利用win10镜像文件安装.net framework 3.5 简单快速
  6. 【数学基础知识】证明三角形的中线交于一点
  7. POJ3349 Snowflake Snow Snowflakes
  8. sco unix系统_什么是SCO UNIX
  9. 16天记住7000考研词汇
  10. ps作图缩小有锯齿的解决方法