这个示例虽然没有相对比较实用的特性,但是表现出来的效果确实非常震撼眼球。先上效果图,让各位同胞感受一下:




特效的表现感很强,有兴趣的读者可以仔细学习一下下面的代码,尝试着理解其中的逻辑。

<!DOCTYPE html>
<html><head><meta charset="utf-8"><title>炫酷粒子变换特效</title><style type="text/css">html,body {width: 100%;height: 100%;margin: 0;padding: 0;overflow: hidden;}.container {width: 100%;height: 100%;margin: 0;padding: 0;background-color: #000000;}</style>
</head><body><div id="container" class="container"></div><script src="https://code.jquery.com/jquery-3.2.1.min.js"></script><script type="text/javascript">var RENDERER = {PARTICLE_COUNT: 1500,PARTICLE_RADIUS: 1,MAX_ROTATION_ANGLE: Math.PI / 60,TRANSLATION_COUNT: 500,init: function(strategy) {this.setParameters(strategy);this.createParticles();this.setupFigure();this.reconstructMethod();this.bindEvent();this.drawFigure();},setParameters: function(strategy) {this.$window = $(window);this.$container = $('#container');this.width = this.$container.width();this.height = this.$container.height();this.$canvas = $('<canvas />').attr({width: this.width,height: this.height}).appendTo(this.$container);this.context = this.$canvas.get(0).getContext('2d');this.center = {x: this.width / 2,y: this.height / 2};this.rotationX = this.MAX_ROTATION_ANGLE;this.rotationY = this.MAX_ROTATION_ANGLE;this.strategyIndex = 0;this.translationCount = 0;this.theta = 0;this.strategies = strategy.getStrategies();this.particles = [];},createParticles: function() {for (var i = 0; i < this.PARTICLE_COUNT; i++) {this.particles.push(new PARTICLE(this.center));}},reconstructMethod: function() {this.setupFigure = this.setupFigure.bind(this);this.drawFigure = this.drawFigure.bind(this);this.changeAngle = this.changeAngle.bind(this);},bindEvent: function() {this.$container.on('click', this.setupFigure);this.$container.on('mousemove', this.changeAngle);},changeAngle: function(event) {var offset = this.$container.offset(),x = event.clientX - offset.left + this.$window.scrollLeft(),y = event.clientY - offset.top + this.$window.scrollTop();this.rotationX = (this.center.y - y) / this.center.y * this.MAX_ROTATION_ANGLE;this.rotationY = (this.center.x - x) / this.center.x * this.MAX_ROTATION_ANGLE;},setupFigure: function() {for (var i = 0, length = this.particles.length; i < length; i++) {this.particles[i].setAxis(this.strategies[this.strategyIndex]());}if (++this.strategyIndex == this.strategies.length) {this.strategyIndex = 0;}this.translationCount = 0;},drawFigure: function() {requestAnimationFrame(this.drawFigure);this.context.fillStyle = 'rgba(0, 0, 0, 0.2)';this.context.fillRect(0, 0, this.width, this.height);for (var i = 0, length = this.particles.length; i < length; i++) {var axis = this.particles[i].getAxis2D(this.theta);this.context.beginPath();this.context.fillStyle = axis.color;this.context.arc(axis.x, axis.y, this.PARTICLE_RADIUS, 0, Math.PI * 2, false);this.context.fill();}this.theta++;this.theta %= 360;for (var i = 0, length = this.particles.length; i < length; i++) {this.particles[i].rotateX(this.rotationX);this.particles[i].rotateY(this.rotationY);}this.translationCount++;this.translationCount %= this.TRANSLATION_COUNT;if (this.translationCount == 0) {this.setupFigure();}}};var STRATEGY = {SCATTER_RADIUS: 150,CONE_ASPECT_RATIO: 1.5,RING_COUNT: 5,getStrategies: function() {var strategies = [];for (var i in this) {if (this[i] == arguments.callee || typeof this[i] != 'function') {continue;}strategies.push(this[i].bind(this));}return strategies;},createSphere: function() {var cosTheta = Math.random() * 2 - 1,sinTheta = Math.sqrt(1 - cosTheta * cosTheta),phi = Math.random() * 2 * Math.PI;return {x: this.SCATTER_RADIUS * sinTheta * Math.cos(phi),y: this.SCATTER_RADIUS * sinTheta * Math.sin(phi),z: this.SCATTER_RADIUS * cosTheta,hue: Math.round(phi / Math.PI * 30)};},createTorus: function() {var theta = Math.random() * Math.PI * 2,x = this.SCATTER_RADIUS + this.SCATTER_RADIUS / 6 * Math.cos(theta),y = this.SCATTER_RADIUS / 6 * Math.sin(theta),phi = Math.random() * Math.PI * 2;return {x: x * Math.cos(phi),y: y,z: x * Math.sin(phi),hue: Math.round(phi / Math.PI * 30)};},createCone: function() {var status = Math.random() > 1 / 3,x,y,phi = Math.random() * Math.PI * 2,rate = Math.tan(30 / 180 * Math.PI) / this.CONE_ASPECT_RATIO;if (status) {y = this.SCATTER_RADIUS * (1 - Math.random() * 2);x = (this.SCATTER_RADIUS - y) * rate;} else {y = -this.SCATTER_RADIUS;x = this.SCATTER_RADIUS * 2 * rate * Math.random();}return {x: x * Math.cos(phi),y: y,z: x * Math.sin(phi),hue: Math.round(phi / Math.PI * 30)};},createVase: function() {var theta = Math.random() * Math.PI,x = Math.abs(this.SCATTER_RADIUS * Math.cos(theta) / 2) + this.SCATTER_RADIUS / 8,y = this.SCATTER_RADIUS * Math.cos(theta) * 1.2,phi = Math.random() * Math.PI * 2;return {x: x * Math.cos(phi),y: y,z: x * Math.sin(phi),hue: Math.round(phi / Math.PI * 30)};}};var PARTICLE = function(center) {this.center = center;this.init();};PARTICLE.prototype = {SPRING: 0.01,FRICTION: 0.9,FOCUS_POSITION: 300,COLOR: 'hsl(%hue, 100%, 70%)',init: function() {this.x = 0;this.y = 0;this.z = 0;this.vx = 0;this.vy = 0;this.vz = 0;this.color;},setAxis: function(axis) {this.translating = true;this.nextX = axis.x;this.nextY = axis.y;this.nextZ = axis.z;this.hue = axis.hue;},rotateX: function(angle) {var sin = Math.sin(angle),cos = Math.cos(angle),nextY = this.nextY * cos - this.nextZ * sin,nextZ = this.nextZ * cos + this.nextY * sin,y = this.y * cos - this.z * sin,z = this.z * cos + this.y * sin;this.nextY = nextY;this.nextZ = nextZ;this.y = y;this.z = z;},rotateY: function(angle) {var sin = Math.sin(angle),cos = Math.cos(angle),nextX = this.nextX * cos - this.nextZ * sin,nextZ = this.nextZ * cos + this.nextX * sin,x = this.x * cos - this.z * sin,z = this.z * cos + this.x * sin;this.nextX = nextX;this.nextZ = nextZ;this.x = x;this.z = z;},rotateZ: function(angle) {var sin = Math.sin(angle),cos = Math.cos(angle),nextX = this.nextX * cos - this.nextY * sin,nextY = this.nextY * cos + this.nextX * sin,x = this.x * cos - this.y * sin,y = this.y * cos + this.x * sin;this.nextX = nextX;this.nextY = nextY;this.x = x;this.y = y;},getAxis3D: function() {this.vx += (this.nextX - this.x) * this.SPRING;this.vy += (this.nextY - this.y) * this.SPRING;this.vz += (this.nextZ - this.z) * this.SPRING;this.vx *= this.FRICTION;this.vy *= this.FRICTION;this.vz *= this.FRICTION;this.x += this.vx;this.y += this.vy;this.z += this.vz;return {x: this.x,y: this.y,z: this.z};},getAxis2D: function(theta) {var axis = this.getAxis3D(),scale = this.FOCUS_POSITION / (this.FOCUS_POSITION + axis.z);return {x: this.center.x + axis.x * scale,y: this.center.y - axis.y * scale,color: this.COLOR.replace('%hue', this.hue + theta)};}};$(function() {RENDERER.init(STRATEGY);});</script>
</body></html>

H5炫酷特效系列4——炫酷粒子变化特效相关推荐

  1. H5炫酷特效系列2——canvas特效-炫酷的心

    之前已经有了一个满屏幕红心的案例,这次带来一个更加炫酷的心型炫酷动效,直接上图,有兴趣的就继续往下看,没兴趣直接过. 屏幕上眼花缭乱的心,不停的冲击着你的视线,让那些少女心砰砰直跳,绝对表白利器,同志 ...

  2. 对一些常见的HTML5特效进行整理和运行(有趣特效,烟花特效,爱心特效,炫酷特效)

    有趣特效 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="en&quo ...

  3. onenote 模板_onenote实用?炫酷功能系列篇②:用插件让效率翻倍

    对我而言,onenote作为office系列的一员,最大的遗憾就是--竟然不支持VBA!office如此强大的一个通用神器,在onenote这里竟然直接被砍了.好在还有个替代品--Onetastic, ...

  4. 超酷的计步器APP(一)——炫酷功能实现,自定义水波纹特效、自定义炫酷开始按钮、属性动画的综合体验

    超酷的计步器APP(一)--炫酷功能实现,自定义水波纹特效.自定义炫酷开始按钮.属性动画的综合体验 好久没写博客了,没给大家分享技术了,真是有些惭愧.这段时间我在找工作,今年Android的行情也不怎 ...

  5. 153.炫酷粒子背景特效

    效果 (源码网盘地址在最后) 最近开源了一个 Vue 组件,还不够完善,欢迎大家来一起完善它,也希望大家能给个 star 支持一下,谢谢各位了. github 地址:https://github.co ...

  6. 字 掉落 炫酷 网站_10大炫酷的HTML5文字动画特效欣赏

    文字是网页中最基本的元素,在CSS2.0时代,我们只能在网页上展示静态的文字,只能改变他的大小和颜色,显得枯燥无味.随着HTML5的发展,现在网页中的文字样式变得越来越丰富了,甚至出现了文字动画,HT ...

  7. 10款超炫html5游戏,10款炫酷的HTML5动画特效,附源码

    HTML5确实非常强大,很多时候我们可以利用HTML5中的新技术实现非常炫酷效果时,这些效果也非常消耗电脑的CPU,但是这些HTML5效果确实能给用户带来不一样的用户体验. 今天我要跟大家分享一些HT ...

  8. [开源项目]Android_炫酷的3D音乐播放器_各种特效OpenGL

    这是 我见过最炫的一个音乐播放器了.里面包含各种特效OpenGL,先上图片...看看大家的反应. 3Dmusic3.png(48.63 KB, 下载次数: 34) 炫酷的3D音乐播放器_各种特效Ope ...

  9. 游戏特效,只管炫酷炸裂就完事了!??

    01.游戏特效的定义 "游戏特效应该如何定义?"为了探寻这个问题的答案,我分开问了几个认识的特效设计师朋友,他们几个人给我的回答是这样的: 朋友A认为,所谓游戏中的特效,是指通过视 ...

最新文章

  1. RPA实施过程中可能会遇到的14个坑
  2. C语言不用strcmp函数比较字符串大小
  3. 你现在还在使用刷脸支付吗?不,刷手支付已来!!!不侵犯隐私、秒速支付...
  4. Winform获取应用程序的当前路径的方法集合,具体如下,值得收藏
  5. tf.reduce_sum()_tf.reduce_mean()_tf.reduce_max()
  6. 【已解决】Navicat 远程连接 Linux服务器上的MySQL数据库
  7. 使用maven时报错Dynamic Web Module 3.1 requires Java 1.7 or newe
  8. 沉浸式全息本是什么_“全息投影”走进健身房,打造沉浸式健身体验室,想来试试吗?...
  9. vue --- 前端代理发送http请求
  10. 明科在线客服系统PHP_在线客服系统的标准功能有哪些
  11. CAN笔记(21) 服务数据对象
  12. jinja Template Synopsis
  13. dumpbin命令问题的解决办法【原】
  14. 互联网大厂最常见的面试算法题大集合
  15. python中给变量赋值时、既确定了变量的值_python中将函数赋值给变量时需要注意的一些问题...
  16. 昆仑mcgs 通讯控制台达B2伺服采用modbus rtu方式,昆仑屏直接控制台达b2伺服的正反转,停止及速度设定,简单好上手
  17. mysql数据导出insert_mysql 数据导出
  18. 如何更改微信标签名字_微信标签怎么设置?微信怎么批量设置好友标签?
  19. 计算机背景图片保存在哪里,Win10桌面背景图片保存在哪个文件夹
  20. QCC3040---UI tones module

热门文章

  1. linux运维命令日志管理,Linux运维实战第二天:Linux基础命令之文件处理命令
  2. QCostomPlot 示例注解 3
  3. 按键检测框架单击-双击-连按
  4. CButton相关函数介绍
  5. 【UCOSIII】一、任务创建、删除、挂起、恢复、任务管理
  6. json解析数组 nlohmann_json解析数组 nlohmann_Nlohmann json学习
  7. oracle输入命令为什么显示2,oracle安装后完善2-2 sqlplus配置变量 命令提示符如何显示为用户名...
  8. lammps计算聚合物例子_LAMMPS中的系综(NPT/NVT)命令
  9. 计算机基础--操作系统基础
  10. Revit二次开发The symbol is not active