特效描述: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彩色流动线条动画特效相关推荐

  1. html 产生烟雾效果,html5 canvas抽象模糊烟雾动画特效

    特效描述:html5 canvas 抽象模糊 烟雾动画特效.html5 canvas绘制彩色模糊的烟雾动画.抽象模糊的烟雾动画特效 代码结构 1. 引入CSS 2. 引入JS 3. HTML代码 vo ...

  2. html画布敲碎的视频,html5 canvas碎纸屑空中飘落动画特效

    特效描述:html5 canvas碎纸屑 空中飘落动画特效.canvas绘制空中飘落的纸屑动画特效. 代码结构 1. HTML代码 "use strict"; var _creat ...

  3. html5 雨滴效果,html5 canvas下雨滴掉落动画特效

    特效描述:html5 canvas 雨滴掉落动画 动画特效.html5 canvas绘制下雨场景动画.雨滴动画. 代码结构 1. 引入JS 2. HTML代码 // TO DO // Remove r ...

  4. php实现下雪场景,html5 canvas逼真下雪场景动画特效

    这是一款效果十分逼真的html5 canvas下雪场景动画特效插件.这款下雪特效是基于Jason Brown的Snowfall jquery plugin的基础上制作的.在Snowfall jquer ...

  5. html语音播放动画,html5 canvas+js音频可视化动画特效

    html5 canvas+js实现的音频可视化动画特效,选择一首本地音频文件播放查看效果. 查看演示 下载资源: 13 次 下载资源 下载积分: 20 积分 js代码 window.onload = ...

  6. 基于 HTML5 Canvas 实现的文字动画特效

    前言 文字是网页中最基本的元素,一般我们在网页上都是展示的静态文字,但是就效果来说,还是比较枯燥的.文字淡入淡出的动画效果在项目中非常实用,如果有某些关键的文字,可以通过这种动态的效果来提醒用户阅读. ...

  7. android 五彩纸屑动画,HTML5 Canvas五彩纸屑粒子动画特效

    JavaScript 语言: JaveScriptBabelCoffeeScript 确定 const getRandom = (min, max) => { return Math.rando ...

  8. html5 canvas实现雷达扫描动画特效

    先看一下最终效果 实现思路 绘制4个圆 绘制一个十字线 绘制一个扫描的指针 让指针转起来 雷达构造函数 function Radar(){this.renderArr=[];//待渲染对象存储数组th ...

  9. html5 canvas时光隧道3D粒子动画js特效

    下载地址 html5 canvas时光隧道3D粒子动画特效是一款非常酷炫的3D粒子时光穿梭视觉冲击动画特效. dd:

  10. html5 canvas网页下雨场景动画js特效

    下载地址一款透明的html5 canvas网页下雨场景动画特效,有意思的是按钮就像雨伞一样可以挡住雨水. dd:

最新文章

  1. Android开发教程 - 使用Data Binding(二)集成与配置
  2. SNMP协议5种报文
  3. 冒泡排序java代码_看动画学算法之:排序冒泡排序
  4. 红帽虚拟化RHEV-PXE批量安装RHEV-H
  5. TLS--线程局部存储
  6. boost::range::istream_range相关的测试程序
  7. 淘宝技术架构从1.0到4.0的演变
  8. LVS负载均衡DR模式实现
  9. 第五篇:Spring Boot整合filter
  10. 鸣人的影分身(信息学奥赛一本通-T1303)
  11. mysql三高讲解(二):2.3 InnoDB索引即数据
  12. 产品泛滥的时代,如何让你的产品脱颖而出?
  13. 指针知识(四):指针数学计算
  14. 毕设题目:Matlab肌电信号
  15. 基于SSM的汽车租赁系统
  16. 外汇兑换人民币业务的居民
  17. protobuf的GZIP压缩
  18. 聚焦数字经济新基建,复杂美再获认可
  19. 转眼间十年过去了,还记得曾经红遍大江南北的这首歌吗?
  20. TPT又一次重量级更新——TPT16使嵌入式测试变得更加轻松

热门文章

  1. MSP430F415IRTDR
  2. Ubuntu桌面快捷方式
  3. 塔米狗知识|企业合并和企业并购是一样的吗?
  4. 贝叶斯判别分析,Python代码分类讲解
  5. 计算机程序班搞笑口号,16字高一班级搞笑口号.docx
  6. Matter 研讨会回顾(第二期)|乐鑫 Matter SDK 开发平台介绍和使用
  7. PHP 接入微信公众账号API
  8. Dropbox安装包官网下载失败的解决方法
  9. 读书百客:《陋室铭》赏析
  10. 如何运行python 复制粘贴_Python执行选择性粘贴