html爱心特效代码教程

article/2025/8/20 17:38:54

一、图片展示

 

二、使用教程

1.桌面新建文本文档

2.将以下代码放入

3.将后缀改为.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: rgba(243, 144, 215, 0.162);

}

canvas {

  position: absolute;

  width: 100%;

  height: 100%;

}

  </style>

 </HEAD>

 <BODY>

  <canvas id="pinkboard"></canvas>

  <script>

  /*

 * Settings

 */

var settings = {

  particles: {

    length:   500, // maximum amount of particles

    duration:   2, // particle duration in sec

    velocity: 100, // particle velocity in pixels/sec

    effect: -0.75, // play with this for a nice effect

    size:      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 pool

    particles = 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 queue

    firstFree++;

    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 particles

    if (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 particles

    while (particles[firstActive].age >= duration && firstActive != firstFree) {

      firstActive++;

      if (firstActive == particles.length) firstActive = 0;

    }

   

   

  };

  ParticlePool.prototype.draw = function(context, image) {

    // draw active particles

    if (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/sec

      time;

  // get point on heart with -PI <= t <= PI

  function 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 canvas

  var 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 path

    function 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 path

    context.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 fill

    context.fillStyle = '#ea80b0';

    context.fill();

    // create the image

    var image = new Image();

    image.src = canvas.toDataURL();

    return image;

  })();

  // render that thing!

  function render() {

    // next animation frame

    requestAnimationFrame(render);

   

    // update time

    var newTime   = new Date().getTime() / 1000,

        deltaTime = newTime - (time || newTime);

    time = newTime;

   

    // clear canvas

    context.clearRect(0, 0, canvas.width, canvas.height);

   

    // create new particles

    var 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 particles

    particles.update(deltaTime);

    particles.draw(context, image);

  }

  // handle (re-)sizing of the canvas

  function onResize() {

    canvas.width  = canvas.clientWidth;

    canvas.height = canvas.clientHeight;

  }

  window.onresize = onResize;

  // delay rendering bootstrap

  setTimeout(function() {

    onResize();

    render();

  }, 10);

})(document.getElementById('pinkboard'));

  </script>

 </BODY>

</HTML>


http://chatgpt.dhexx.cn/article/hxZMCThc.shtml

相关文章

html爱心特效代码

New Document /* * RequestAnimationFrame polyfill by Erik Mller */ (function(){var b0;var c[“ms”,“moz”,“webkit”,“o”];for(var a0;a<c.length&&!window.requestAnimationFrame;a){window.requestAnimationFramewindow[c[a]“RequestAnimationFrame”…

html简单特效代码,html特效代码大全

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 23. 永远都会带着框架 if (window top)top.location.href "frames.htm"; //frames.htm为框架网页 // --> 24. 防止被人frame if (top.location ! self.location)top.locationself.location; // --> 25. 网页将不…

Android 科大讯飞 语音听写

这几天在搞一个语音识别的项目 用到i的是科大讯飞的语音服务&#xff0c;第一次搞语音识别&#xff0c;在这里记录一下&#xff0c;也希望对大家有用。废话不多说进入正题 一、要用到科大讯飞的语音识别功能&#xff0c;肯定是要他的开发者平台申请账号&#xff0c;创建应用&a…

Python调用科大讯飞语音听写的SDK包

一、如何下载科大讯飞语音听写的SDK包 1.1、注册下载语音听写SDK包 **第一步&#xff1a;**登录讯飞开放平台&#xff0c;找到产品服务——“语音听写”&#xff0c;点击“立即开通” **第二步&#xff1a;**创建新应用 **第三步&#xff1a;**创建应用&#xff0c;填写信息…

C# 实现语音听写

本文系原创&#xff0c;禁止转载。 分享如何使用c#对接科大讯飞语音听写服务&#xff0c;简单高效地实现语音听写。 实现语音听写主要分为录音和语音识别两部分&#xff1b;录音是指获取设备声卡端口的音频数据并将之保存为音频文件&#xff0c;语音识别就是将刚才所述的音频文…

讯飞语音听写

第一步&#xff1a;将下载好的Sdk解压&#xff0c;将压缩文件中的libs下的jar文件放到项目中的libs包下&#xff0c;将压缩文件中的lisb下除jar文件放到main下的jniLibs包中 第二步&#xff1a;Sdk初始化,建议选择在自定义的application中初始化。 //初始化讯飞语音SpeechUtil…

讯飞语音——带你简单实现语音听写

语音听写 de 简单实现 一、前言 如果你没有在讯飞语音平台上创建应用&#xff0c;请先参考讯飞语音的详细配置使用 二、功能描述 语音听写和语音合成都是较为基础也是最常使用的两个基本功能。 语音合成是将文本转化为语音说出来&#xff0c;就是读文章。 语音听写是什么呢&a…

使用讯飞实现语音听写与语音合成功能

一、准备工作 1、首先你需要去科大讯飞的官网去注册一个账号&#xff0c;怎么注册我就不说了&#xff0c;然后去控制台&#xff0c;创建新应用。 2、下载对应的sdk&#xff0c;点击sdk下载&#xff0c;记住这里的APPID码&#xff0c;sdk初始化要用。 3、下载语音听写和在线语…

科大讯飞语音听写在vue2中的使用

安装 worker-loader版本是2.0.0 vue.config.js的配置如下chainWebpack:(config)=>{config.output.globalObject("this"); }, configureWebpack: (config) => {config.module.rules.push({test: /\.worker.js$/,use: {loader: "worker-loader",option…

vue+科大讯飞语音听写功能(解决针对vue new Worker报错问题)

参考1&#xff1a;vue科大讯飞语音听写功能(解决针对vue new Worker报错问题)_Other world的博客-CSDN博客 参考2&#xff1a;vue中使用web worker - Gerryli - 博客园 参考3&#xff1a;将PC浏览器、ZOOM等软件正在播放的音频实时转成文字&#xff01;讯飞语音输入法的妙用 -…

Unity2021接入讯飞语音听写(Android)

使用的引擎工具&#xff1a; Unity2021.3.19 android-studio-2021.1.21 第一步&#xff1a; 新建一个Android项目&#xff08;工程名字随便啦&#xff09; 然后新建一个library &#xff08;同上&#xff0c;库名自己命名吧&#xff09; Android环境目前就算是初步建立好了。 …

vue2中接入讯飞语音听写

首先先登录https://www.xfyun.cn/&#xff0c;在控制台中创建自己的app&#xff0c;并且拿到APPID。 下载crypto-js 与线程worker npm install crypto-js npm install worker-loader 官网中有示例文件&#xff0c;稍微改造一下&#xff0c;封装成组件就能使用了。 transco…

Java 接入讯飞语音听写Speech to Text(STT)功能

标题 讯飞认证配置封装监听器客户端工具 Speech2TextClient.java 对外开放接口对外开放接口实现结果参考 根据官方提供的 WebIATWS 工具扩展修改&#xff0c;接入了讯飞的语音听写(STT)服务 讯飞认证配置 public class XFAuthorityConfig {public static final String hostUr…

html5语音听写流式,iOS 讯飞语音听写(流式版)

最近项目中用到了讯飞的语音识别,然后稍微看了一下,里面有几个值得注意的点,记录一下,先说语音听写(流式版),实时语音转写后期会附上 ,文末有 demo //语音听写(流式版) 语音听写流式版其实没设么好说的,因为直接有 SDK,导入项目就可以了,需要注意的点就是每个创建的 APP 和 SDK…

科大讯飞语音听写(Android)

前面就不废话了&#xff0c;像申请应用&#xff0c;获取SDK等等&#xff0c;我相信大家应该都会的&#xff0c;科大讯飞采用的是两种语音听写功能,一种带有UI&#xff0c;一种没有UI&#xff0c;本人还是比较笨的&#xff0c;所以就写了较为简单的不带UI的语音听写&#xff0c;…

语音转写和语音听写_如何在Windows 10上使用语音听写

语音转写和语音听写 Windows 10’s Fall Creators Update makes voice dictation much easier to use. Now, you can immediately begin dictation by pressing a key WindowsH on your keyboard. You don’t have to dig through the Control Panel and set anything up first…

【超简单】之基于PaddleSpeech搭建个人语音听写服务

一、【超简单】之基于PaddleSpeech搭建个人语音听写服务 1.需求分析 亲们&#xff0c;你们要写会议纪要嘛&#xff1f;亲们&#xff0c;你们要写会议纪要嘛&#xff1f;亲们&#xff0c;你们要写会议纪要嘛&#xff1f; 当您面对成吨的会议录音&#xff0c;着急写会议纪要而…

遥感技术及高分遥感影像在地震中的应用及高分二号获取

长期以来&#xff0c;地震预报监测、灾害调查、灾情信息获取主要依靠实地勘测手段&#xff0c;其获取的数据精度和置信度虽然较高&#xff0c;但存在工作量大、效率低、费用高和信息不直观等缺点。遥感技术手段可在一定程度上克服传统实地勘测手段的缺点&#xff0c;并具有其他…

高分一号(GF-1)-中国高分辨率对地观测系统的第一颗卫星

2013年4月26日12时13分04秒由长征二号丁运载火箭成功发射&#xff0c;开启了中国对地观测的新时代。卫星全色分辨率是2米&#xff0c;多光谱分辨率为8米。高分一号卫星的宽幅多光谱相机幅宽达到了800公里。 “高分一号”的特点是增加了高分辨率多光谱相机&#xff0c;该相机的性…

历年(2017-2022)国产陆地观测卫星(高分1号2号6号等)外场绝对辐射定标系数

国产卫星绝对辐射定标系数&#xff08;2008——2022&#xff09; 2017年 参考博文&#xff1a;高分一号/二号/六号定标系数_desertsTsung的博客-CSDN博客