html彩色条,html5 canvas彩色流动线条动画特效
特效描述:html5 canvas 彩色流动线条 动画特效。html5彩色线条动画,流动线条特效
代码结构
1. 引入JS
2. HTML代码
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var ui = {};
var count = 150;
var particles = [];
var mouseVisible = false;
var mouse = undefined;
var voronoi = undefined;
var canvas = undefined;
function setup() {
canvas = createCanvas(windowWidth, windowHeight);
canvas.elt.onmouseenter = mouseEnter.bind(null, true);
canvas.elt.onmouseleave = mouseEnter.bind(null, false);
ui.particles = createCheckbox('Particles', true);
ui.trail = createCheckbox('Trails', true);
ui.mouse = createCheckbox('Mouse', false);
ui.voronoi = createCheckbox('Voronoi', false);
ui.addParticle = createButton('Add 10 Particles');
ui.addParticle.mousePressed(function () {
for (var i = 0; i < 10; i++) {
addParticle();
}
});
var optionsContainer = document.getElementById('options');
Object.values(ui).forEach(function (n) {
return optionsContainer.appendChild(n.elt);
});
fillBackground();
colorMode(HSB);
for (var i = 0; i < count; i++) {
addParticle();
}
setupVoronoi();
}
function addParticle() {
var particle = new Particle();
particle.pos.set(random(width), random(height));
particles.push(particle);
return particle;
}
function setupVoronoi() {
voronoi = d3.voronoi().extent([[0, 0], [width, height]]);
}
function fillBackground() {
background(0);
}
function draw() {
if (ui.trail.checked()) {
fill(0, 0.05);
noStroke();
rect(0, 0, width, height);
} else {
fillBackground();
}
if (ui.mouse.checked() && mouseVisible) {
mouse = createVector(mouseX, mouseY);
}
if (ui.voronoi.checked()) {
drawVoronoi();
}
handleParticles();
}
function mouseEnter(visibility) {
mouseVisible = visibility;
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
setupVoronoi();
}
function drawVoronoi() {
noFill();
stroke(255, 0.2);
var points = particles.map(function (n) {
return n.point();
});
var v = voronoi(points);
beginShape(LINES);
v.edges.forEach(function (n) {
vertex.apply(undefined, n[0]);
vertex.apply(undefined, n[1]);
});
endShape();
}
function handleParticles() {
noStroke();
var z = frameCount / 400;
particles.forEach(function (n, i) {
var heading = n.vel.heading();
if (ui.particles.checked()) {
var hu = map(heading, -PI, PI, 0, 360);
fill(hu, 100, 100);
n.show();
}
var noiseInfluence = noise(n.pos.x / 100, n.pos.y / 100, z);
var force = map(noiseInfluence, 0.3, 0.7, 0, TAU);
var f = p5.Vector.fromAngle(force).setMag(0.03);
n.applyForce(f);
if (ui.mouse.checked()) {
applyMouseInfluence(n);
}
n.update();
n.edges();
});
}
function applyMouseInfluence(particle) {
if (mouseVisible) {
var force = p5.Vector.sub(mouse, particle.pos);
var f = force.setMag(0.035);
particle.applyForce(f);
}
}
var Particle = function () {
function Particle() {
_classCallCheck(this, Particle);
this.pos = createVector(0, 0);
this.acc = createVector(0, 0);
this.vel = createVector(0, 0);
}
Particle.prototype.applyForce = function applyForce() {
var _acc;
(_acc = this.acc).add.apply(_acc, arguments);
};
Particle.prototype.update = function update() {
this.vel.add(this.acc);
this.acc.mult(0);
this.pos.add(this.vel);
this.vel.mult(0.99);
};
Particle.prototype.edges = function edges() {
if (this.pos.x < 0) {
this.pos.x += width;
} else if (this.pos.x > width) {
this.pos.x -= width;
}
if (this.pos.y < 0) {
this.pos.y += height;
} else if (this.pos.y > height) {
this.pos.y -= height;
}
};
Particle.prototype.point = function point() {
var _this = this;
return ['x', 'y'].map(function (n) {
return _this.pos[n];
});
};
Particle.prototype.vertex = function (_vertex) {
function vertex() {
return _vertex.apply(this, arguments);
}
vertex.toString = function () {
return _vertex.toString();
};
return vertex;
}(function () {
vertex.apply(undefined, this.point());
});
Particle.prototype.show = function show() {
// point(...this.point());
ellipse.apply(undefined, this.point().concat([4]));
};
return Particle;
}();
html彩色条,html5 canvas彩色流动线条动画特效相关推荐
- html 产生烟雾效果,html5 canvas抽象模糊烟雾动画特效
特效描述:html5 canvas 抽象模糊 烟雾动画特效.html5 canvas绘制彩色模糊的烟雾动画.抽象模糊的烟雾动画特效 代码结构 1. 引入CSS 2. 引入JS 3. HTML代码 vo ...
- html画布敲碎的视频,html5 canvas碎纸屑空中飘落动画特效
特效描述:html5 canvas碎纸屑 空中飘落动画特效.canvas绘制空中飘落的纸屑动画特效. 代码结构 1. HTML代码 "use strict"; var _creat ...
- html5 雨滴效果,html5 canvas下雨滴掉落动画特效
特效描述:html5 canvas 雨滴掉落动画 动画特效.html5 canvas绘制下雨场景动画.雨滴动画. 代码结构 1. 引入JS 2. HTML代码 // TO DO // Remove r ...
- php实现下雪场景,html5 canvas逼真下雪场景动画特效
这是一款效果十分逼真的html5 canvas下雪场景动画特效插件.这款下雪特效是基于Jason Brown的Snowfall jquery plugin的基础上制作的.在Snowfall jquer ...
- html语音播放动画,html5 canvas+js音频可视化动画特效
html5 canvas+js实现的音频可视化动画特效,选择一首本地音频文件播放查看效果. 查看演示 下载资源: 13 次 下载资源 下载积分: 20 积分 js代码 window.onload = ...
- 基于 HTML5 Canvas 实现的文字动画特效
前言 文字是网页中最基本的元素,一般我们在网页上都是展示的静态文字,但是就效果来说,还是比较枯燥的.文字淡入淡出的动画效果在项目中非常实用,如果有某些关键的文字,可以通过这种动态的效果来提醒用户阅读. ...
- android 五彩纸屑动画,HTML5 Canvas五彩纸屑粒子动画特效
JavaScript 语言: JaveScriptBabelCoffeeScript 确定 const getRandom = (min, max) => { return Math.rando ...
- html5 canvas实现雷达扫描动画特效
先看一下最终效果 实现思路 绘制4个圆 绘制一个十字线 绘制一个扫描的指针 让指针转起来 雷达构造函数 function Radar(){this.renderArr=[];//待渲染对象存储数组th ...
- html5 canvas时光隧道3D粒子动画js特效
下载地址 html5 canvas时光隧道3D粒子动画特效是一款非常酷炫的3D粒子时光穿梭视觉冲击动画特效. dd:
- html5 canvas网页下雨场景动画js特效
下载地址一款透明的html5 canvas网页下雨场景动画特效,有意思的是按钮就像雨伞一样可以挡住雨水. dd:
最新文章
- Android开发教程 - 使用Data Binding(二)集成与配置
- SNMP协议5种报文
- 冒泡排序java代码_看动画学算法之:排序冒泡排序
- 红帽虚拟化RHEV-PXE批量安装RHEV-H
- TLS--线程局部存储
- boost::range::istream_range相关的测试程序
- 淘宝技术架构从1.0到4.0的演变
- LVS负载均衡DR模式实现
- 第五篇:Spring Boot整合filter
- 鸣人的影分身(信息学奥赛一本通-T1303)
- mysql三高讲解(二):2.3 InnoDB索引即数据
- 产品泛滥的时代,如何让你的产品脱颖而出?
- 指针知识(四):指针数学计算
- 毕设题目:Matlab肌电信号
- 基于SSM的汽车租赁系统
- 外汇兑换人民币业务的居民
- protobuf的GZIP压缩
- 聚焦数字经济新基建,复杂美再获认可
- 转眼间十年过去了,还记得曾经红遍大江南北的这首歌吗?
- TPT又一次重量级更新——TPT16使嵌入式测试变得更加轻松