爱心源码动图-Html网页运行
程序示例精选
爱心源码动图-Html网页运行
如需安装运行环境或远程调试,见文章底部微信名片!
前言
Html写的追女生神器-爱心动图,代码整洁,规则,易读,对学习与使用Html有较好的帮助。
文章目录
一、所需工具软件
二、使用步骤
1. Head属性代码定义
2. 参数设置
3. 爱心函数
4. 运行结果
三、在线协助
一、所需工具软件
1. 谷歌浏览器
2. Microsoft Edge浏览器
二、使用步骤
1.Head属性代码定义
代码如下(示例):
<!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>
2.参数设置
代码如下(示例):
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},
};
该处使用的url网络请求的数据。
3.爱心函数:
代码如下(示例):
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.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>
4.运行结果如下:
三、在线协助:
如需安装运行环境或远程调试,见文章底部微信名片!
爱心源码动图-Html网页运行相关推荐
- Python爱心源码抖动图
程序示例精选 Python爱心源码动图 如需安装运行环境或远程调试,见文章底部微信名片! 前言 Python写的追女生神器-爱心动图,代码整洁,规则,易读,对学习与使用Python有较好的帮助. 文章 ...
- vue3版本的爱心源码
老婆:你会爱心源码吗? 我:(一脸懵逼)啥? 老婆:就是用代码花个爱心,小垃圾 我:这不是本科生基操吗?能难得住我?说吧,要什么样的.什么色儿的爱心. 脑海里,已经开始构思用纯css画还是用svg,要 ...
- 闪动爱心源码(Python)
闪动爱心源码 效果: import random from math import sin, cos, pi, log from tkinter import *CANVAS_WIDTH = 640 ...
- python制作动图、怎么运行_漫画:如何分析运行中的 Python 程序?
漫画:如何分析运行中的 Python 程序? 内容简介如何使用 py-spy 如何读懂火焰图 遇到的问题 大佬组长透露出几个关键信息:1. 要排查的是线上服中正在运行的 Python 程序 2.&qu ...
- Python绘制表白爱心源码【女神看了绝对不会拒绝的你的表白嘿嘿】
一个人在沙漠里快要饿死了,这时他捡到了神灯. 神灯:"我只可以实现你一个愿望,快说吧,我赶时间." 人:"我要老婆--" 神灯立刻变出一个美女,然后不屑的说:& ...
- python制作动图、怎么运行_用Python2.7运行下面这个代码,但是出现了问题,请问如何可以解决,使之生成图像?...
Process finished with exit code -1073741795 (0xC000001D) 这是什么意思,如何可以解决这个问题. import numpy as np from ...
- 《萌小甜动图字帖》使用简介
这个软件可以帮助需要练字的各位大小朋友. 孩子练好字,父母少操心. 软件界面简单,直接输入需要查询笔顺和米字字帖的文字,然后按生成,即可以打开一个浏览器,在浏览器中显示字帖. 软件特点: 自助生成动图 ...
- python二维码加动态图_用python自制个性二维码(设置带LOGO的二维码带动图)
本文使用的是 python3.6 MyQR库 tkinter库 我们可以使用MyQR这个库 安装方式如下: 进入命令行输入: pip3 install MyQR 如果安装不成功多半是网络有问题,可以去 ...
- 动态箭头gif图标_GIF动图修改教程,超详细
大家好,我是阿牛,欢迎大家看我的文章,从今天开始,阿牛会给大家分享一些好玩的APP和各种电脑.手机.办公.学习等一些资源,希望大家支持. 一直有朋友看到喜欢的GIF动图想改上面的字,看到别人发的动图表 ...
最新文章
- Centos6.3修改源码遇到无法yum安装的问题
- 14、HTML <input>标签
- SPOJ - DQUERY D-query(莫队/线段树+离线/主席树)
- python 文件分割 按大小_python处理分隔大文件
- ssh密钥代理转发(ssh agent forwarding)
- “我花了 5 年时间编写自己的操作系统!”
- Electron开发桌面应用
- 产品配件类目税目分类_商品及税收分类编码选择技巧
- Ubuntu18.04安装Oracle11g
- 基于Android的Word在线预览
- Auto.js微信抢红包脚本
- 几何实体图形保存成stl格式的ascII和二进制文。用Vc++语言读入文件,给三角网格坐标值乘以2,并保存到另一stl文件。输出完成工作所用的执行时间
- 计算机信息系统用户管理规定,计算机信息系统保密管理暂行办法 | 中华全国商业信息中心...
- Foxmail 设置自动落款签名
- php手册中的tokenizer详细总结,基本看它就够了
- Android面试知识总结
- 解决WordPress文章页面无法显示的问题
- 霍涛发现数据科学专业门槛最高,霍涛完善数据实践
- liunx定时清理运行内存脚本
- js for循环 遍历数组 遍历对象属性
热门文章
- 恢复已删除文件的 10 种安卓数据恢复工具
- /tmp目录下出现system-private文件夹解决方法
- PS解决要求96和8之间的整数。已插入最接近的数值的问题
- 2069:【例2.12 】糖果游戏
- 点量广告插播系统-随时在IPTV系统或者电视盒智能电视中插播广告
- 从零开始制作【立体键盘】,画UI免写CSS,【盲打练习】的交互逻辑只用了10来行表达式
- 高德地图水纹预警效果;高德地图控制可视行政区域
- 学习笔记——vue3.0中的性能优化
- 哈哈,终于找回来了《手放开》
- 2021.11.15-11.17 周一----周三 java学习日志