html5 canvas 烟花,html5 canvas酷炫的烟花爆炸动画特效
特效描述:html5canvas 酷炫的 烟花爆炸动画特效。html5点击页面烟花爆炸动画,3D烟花动画,酷炫的烟花特效。
代码结构
1. 引入JS
2. HTML代码
(function() {
var Particles,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
Particles = (function() {
function Particles() {
this.render = bind(this.render, this);
this.rotateRadians = bind(this.rotateRadians, this);
this.random = bind(this.random, this);
this.mouseMove = bind(this.mouseMove, this);
this.mouseDown = bind(this.mouseDown, this);
this.resize = bind(this.resize, this);
this.animate = bind(this.animate, this);
this.setStage = bind(this.setStage, this);
this.setLighting = bind(this.setLighting, this);
this.getTexture = bind(this.getTexture, this);
this.addStars = bind(this.addStars, this);
this.setActors = bind(this.setActors, this);
this.getPastelColor = bind(this.getPastelColor, this);
this.canvasMouse = {
x: 0,
y: 0,
z: 0,
px: 0,
py: 0,
py: 0,
vx: 0,
vy: 0,
pressed: false
};
this.colors = ['#da6b00', '#8555d4', '#4ad3b5', '#ffffff'];
this.particleCount = 500;
this.initialRadius = 0.1;
this.movementSpeed = 2;
this.directions = [];
this.starSystems = [];
this.systemCount = 1;
this.setStage();
this.setLighting();
this.setActors();
setInterval((function(_this) {
return function() {
_this.systemCount++;
return _this.addStars(_this.getPastelColor(), 0, 0);
};
})(this), 5000);
this.animate();
this.render();
}
Particles.prototype.getPastelColor = function() {
this.col = new THREE.Color("hsl(" + (this.random(0, 360)) + ", " + (Math.floor(25 + 70 * Math.random())) + "%, " + (Math.floor(85 + 10 * Math.random())) + "%)");
return "#" + (this.col.getHexString());
};
Particles.prototype.setActors = function() {
return this.addStars(this.getPastelColor(), 0, 0);
};
Particles.prototype.addStars = function(color, x, y) {
var angle, i, k, radiusSQ, ref, vertex;
this.dirs = [];
this.geometry = new THREE.Geometry();
this.materials = new THREE.PointsMaterial({
color: color,
size: 1,
transparent: true,
blending: THREE.AdditiveBlending,
map: this.getTexture(color),
depthTest: false
});
for (i = k = 0, ref = this.particleCount; 0 <= ref ? k < ref : k > ref; i = 0 <= ref ? ++k : --k) {
angle = Math.random() * 2 * Math.PI;
radiusSQ = Math.random() * this.initialRadius * this.initialRadius;
vertex = new THREE.Vector3();
vertex.x = x;
vertex.y = y;
vertex.z = 0;
this.dirs.push({
x: (Math.random() * this.movementSpeed) - (this.movementSpeed / 2),
y: (Math.random() * this.movementSpeed) - (this.movementSpeed / 2),
z: (Math.random() * this.movementSpeed) - (this.movementSpeed / 2)
});
this.geometry.vertices.push(vertex);
}
this.starSystem = new THREE.Points(this.geometry, this.materials);
this.starSystem.sortParticles = true;
this.directions.push(this.dirs);
this.starSystems.push(this.starSystem);
return this.scene.add(this.starSystem);
};
Particles.prototype.getTexture = function(color) {
var canvas, context, gradient, texture;
canvas = document.createElement('canvas');
canvas.width = 32;
canvas.height = 32;
context = canvas.getContext('2d');
gradient = context.createRadialGradient(canvas.width / 2, canvas.height / 2, 0, canvas.width / 2, canvas.height / 2, canvas.width / 2);
gradient.addColorStop(0, 'rgba(255,255,255,1)');
gradient.addColorStop(0.2, color);
gradient.addColorStop(0.4, color);
gradient.addColorStop(1, 'rgba(0,0,0,1)');
context.fillStyle = gradient;
context.fillRect(0, 0, canvas.width, canvas.height);
texture = new THREE.Texture(canvas);
texture.needsUpdate = true;
return texture;
};
Particles.prototype.setLighting = function() {
this.ambientLight = new THREE.AmbientLight("#ffffff", 0.5);
return this.scene.add(this.ambientLight);
};
Particles.prototype.setStage = function() {
this.renderer = new THREE.WebGLRenderer({
canvas: document.getElementById("canvas"),
antialias: true
});
this.renderer.setPixelRatio(window.devicePixelRatio);
this.renderer.autoClear = false;
this.renderer.setSize(window.innerWidth, window.innerHeight);
this.scene = new THREE.Scene();
this.camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 1000);
this.camera.position.z = 50;
this.stats = new Stats();
this.stats.setMode(0);
this.stats.domElement.style.position = 'absolute';
this.stats.domElement.style.left = '0px';
this.stats.domElement.style.top = '0px';
document.getElementById("stats").appendChild(this.stats.domElement);
window.addEventListener('resize', this.resize, false);
window.addEventListener('mousemove', this.mouseMove, false);
return window.addEventListener("mousedown", this.mouseDown);
};
Particles.prototype.animate = function() {
var i, j, k, l, particle, ref, ref1;
for (j = k = 0, ref = this.systemCount - 1; 0 <= ref ? k <= ref : k >= ref; j = 0 <= ref ? ++k : --k) {
for (i = l = 0, ref1 = this.particleCount; 0 <= ref1 ? l < ref1 : l > ref1; i = 0 <= ref1 ? ++l : --l) {
particle = this.starSystems[j].geometry.vertices[i];
particle.x += this.directions[j][i].x;
particle.y += this.directions[j][i].y;
particle.z += this.directions[j][i].z;
}
this.starSystems[j].geometry.verticesNeedUpdate = true;
}
this.stats.update();
this.render();
return requestAnimationFrame(this.animate);
};
Particles.prototype.resize = function() {
this.camera.aspect = window.innerWidth / window.innerHeight;
this.camera.updateProjectionMatrix();
this.renderer.setSize(window.innerWidth, window.innerHeight);
return this.render();
};
Particles.prototype.mouseDown = function() {
this.systemCount++;
return this.addStars(this.getPastelColor(), this.canvasMouse.x, this.canvasMouse.y);
};
Particles.prototype.mouseMove = function() {
this.canvasMouse.px = this.canvasMouse.x;
this.canvasMouse.py = this.canvasMouse.y;
this.canvasX = (event.clientX / window.innerWidth) * 2 - 1;
this.canvasY = -(event.clientY / window.innerHeight) * 2 + 1;
this.vector = new THREE.Vector3(this.canvasX || 0, this.canvasY || 0, 0);
this.vector.unproject(this.camera);
this.dir = this.vector.sub(this.camera.position).normalize();
this.distance = -this.camera.position.z / this.dir.z;
return this.canvasMouse = this.camera.position.clone().add(this.dir.multiplyScalar(this.distance));
};
Particles.prototype.random = function(min, max) {
return Math.floor(Math.random() * max) + min;
};
Particles.prototype.rotateRadians = function(deg) {
return deg * (Math.PI / 180);
};
Particles.prototype.render = function() {
return this.renderer.render(this.scene, this.camera);
};
return Particles;
})();
new Particles;
}).call(this);
html5 canvas 烟花,html5 canvas酷炫的烟花爆炸动画特效相关推荐
- canvas 形状碰撞_【案例】如何用html5 制作canvas酷炫的网状图形动画特效
点击上方[我分享我快乐]→[...]右上角→[设为星标⭐]即可第一时间获取最新设计资源 哈喽大家好,又到了每周二案例环节啦,在教学开始前先插播一条招聘信息~ 高薪招聘 杭州招聘(非技术) 公司背景: ...
- html5 canvas酷炫3D背景打开动画特效
html5 canvas酷炫3D背景打开动画特效 点击跳转到演示地址 点击进入资源下载地址
- 情人节程序员用HTML网页表白【彩色酷炫的空间背景动画特效】 HTML5七夕情人节表白网页源码 HTML+CSS+JavaScript
这是程序员表白系列中的100款网站表白之一,旨在让任何人都能使用并创建自己的表白网站给心爱的人看. 此波共有100个表白网站,可以任意修改和使用,很多人会希望向心爱的男孩女孩告白,生性腼腆的人即使那个 ...
- ae制h5文字动画_html5酷炫的文字打字动画特效
特效描述:html5 酷炫的文字 打字动画特效.html5和css3制作键盘输入文字酷炫的打字动画特效. 代码结构 1. 引入JS 2. HTML代码 0 1 2 3 4 5 6 7 8 9 10 1 ...
- android 漩涡动画,html5 canvas酷炫的粒子漩涡动画特效
特效描述:html5 canvas 粒子漩涡 动画特效.html5粒子漩涡动画,酷炫的粒子动画特效 代码结构 1. HTML代码 function project3D(x,y,z,vars){ var ...
- 纯CSS实现酷炫渐变色、旋转动画特效
一.效果展示 首先来看一下我们最终要实现的效果: 旋转放大: 垂直下落: 旋转掉落: 接下来我们就用CSS进行实现. 二.代码实现 1.定义盒子 此时的效果: 2.添加hover伪类选择器 此时效果: ...
- HTML+CSS+JS实现 ❤️h5酷炫的天体木星动画特效❤️
效果演示: 代码目录: 主要代码实现: 部分CSS样式: body {margin: 0;overflow: hidden;position: relative;width: 100vw;height ...
- html5中如何让一个动画框左右上下浮动,HTML5 SVG如何实现炫酷checkbox复选框动画特效...
简要教程 这是一款HTML5 SVG炫酷checkbox复选框动画特效.该checkbox动画特效使用svg来构建复选框效果,然后通过CSS3动画来控制复选框的选中和取消选中状态,效果非常炫酷. 使用 ...
- html图标动画效果,html5 svg炫酷图标变形动画特效
这是一款效果非常炫酷的html5 svg炫酷图标变形动画特效.类似的效果有:html5 svg和css3超酷图标动画特效. 使用方法 1.添加一组SVG图标到你的HTML文件中. 2.通过调用new ...
最新文章
- 荣耀30pro系统_荣耀30 pro:正式再见!
- fedora20 安装ror
- 使用docker部署flask项目
- php处理结果集,php中mysqli 处理查询结果集的几个方法
- python requests请求终止_Requests 如何中断请求?
- CVE-2020-1472 | Netlogon 特权提升漏洞预警
- 16种oracle查询日期语句
- 只需简单的整理,让你的Mac 更安全、更智能
- 网站服务器和空间大小,网站服务器和空间大小
- egret农场游戏源码
- 微信历史消息java_微信聊天机器人[过年防信息轰炸、自动回复拜年消息]
- python灰色关联度分析代码_GRA灰色关联度分析学习 附python代码
- 网络TCP/IP基础(IP地址与子网划分)
- Spark MLlib数据挖掘2--基础统计分析
- Python gevent学习笔记-2
- odoo 使用打印功能
- ERP Oracle应用
- 数据库系统(DBS)2
- ESD静电保护(ESD器件保护原理及选型)
- Web流程图的绘画指南