• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • dedecms
  • ecshop
  • z-blog
  • UcHome
  • UCenter
  • drupal
  • WordPress
  • 帝国cms
  • phpcms
  • 动易cms
  • phpwind
  • discuz
  • 科汛cms
  • 风讯cms
  • 建站教程
  • 运营技巧
您的位置:首页 > CMS教程 >建站教程 > HTML5 canvas如何绘制酷炫能量线条效果(附代码)

HTML5 canvas如何绘制酷炫能量线条效果(附代码)

作者:站长图库 字体:[增加 减小] 来源:互联网

站长图库向大家介绍了HTML5+canvas,canvas绘制,酷炫能量线条等相关知识,希望对您有所帮助

本篇文章给大家介绍一下使用HTML5 canvas绘制酷炫能量线条特效的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对你们有所助。


611e3bd537785.gif


上面是效果图,下面直接附js代码,希望对大家有所帮助!!

// UTILconst PI = Math.PI,  TWO_PI = Math.PI * 2;const Util = {};Util.timeStamp = function() {  return window.performance.now();};Util.random = function(min, max) {  return min + Math.random() * (max - min);};Util.map = function(a, b, c, d, e) {  return (a - b) / (c - b) * (e - d) + d;};Util.lerp = function(value1, value2, amount) {  return value1 + (value2 - value1) * amount;};Util.clamp = function(value, min, max) {  return Math.max(min, Math.min(max, value));};// Vectorclass Vector {  constructor(x, y) {    this.x = x || 0;    this.y = y || 0;  }  set(x, y) {    this.x = x;    this.y = y;  }  reset() {    this.x = 0;    this.y = 0;  }  fromAngle(angle) {    let x = Math.cos(angle),      y = Math.sin(angle);    return new Vector(x, y);  }  add(vector) {    this.x += vector.x;    this.y += vector.y;  }  sub(vector) {    this.x -= vector.x;    this.y -= vector.y;  }  mult(scalar) {    this.x *= scalar;    this.y *= scalar;  }  p(scalar) {    this.x /= scalar;    this.y /= scalar;  }  dot(vector) {    return vector.x * this.x + vector.y * this.y;  }  limit(limit_value) {    if (this.mag() > limit_value) this.setMag(limit_value);  }  mag() {    return Math.hypot(this.x, this.y);  }  setMag(new_mag) {    if (this.mag() > 0) {      this.normalize();    } else {      this.x = 1;      this.y = 0;    }    this.mult(new_mag);  }  normalize() {    let mag = this.mag();    if (mag > 0) {      this.x /= mag;      this.y /= mag;    }  }  heading() {    return Math.atan2(this.y, this.x);  }  setHeading(angle) {    let mag = this.mag();    this.x = Math.cos(angle) * mag;    this.y = Math.sin(angle) * mag;  }  dist(vector) {    return new Vector(this.x - vector.x, this.y - vector.y).mag();  }  angle(vector) {    return Math.atan2(vector.y - this.y, vector.x - this.x);  }  copy() {    return new Vector(this.x, this.y);  }}// Init canvaslet canvas = document.createElement("canvas"),  ctx = canvas.getContext("2d"),  H = (canvas.height = window.innerHeight),  W = (canvas.width = window.innerWidth);document.body.appendChild(canvas);// Mouselet mouse = {  x: W/2,  y: H/2};canvas.onmousemove = function(event) {  mouse.x = event.clientX - canvas.offsetLeft;  mouse.y = event.clientY - canvas.offsetTop;};document.body.onresize = function(event){  H = (canvas.height = window.innerHeight);  W = (canvas.width = window.innerWidth);}// Let's goclass Arrow {  constructor(x, y, target) {    this.position = new Vector(x, y);    this.velocity = new Vector().fromAngle(Util.random(0,TWO_PI));    this.acceleration = new Vector(0, 0);    this.target = target;    this.travelled_distance = 0;    this.min_size = 1;    this.max_size = 6;    this.size = Util.random(this.min_size, this.max_size);    this.zone = this.size * 4;    this.topSpeed = Util.map(this.size,this.min_size,this.max_size,40,10);    let tailLength = Math.floor(Util.map(this.size, this.min_size, this.max_size, 4, 16));    this.tail = [];    for (let i = 0; i < tailLength; i++) {      this.tail.push({        x: this.position.x,        y: this.position.y      });    }    this.wiggle_speed = Util.map(this.size, this.min_size, this.max_size, 2 , 1.2);    this.blink_offset = Util.random(0, 100);    this.alpha = Util.random(0.1,1)  }  render() {    this.update();    this.draw();  }  update() {    let old_position = this.position.copy();    // Focus on target    let t = new Vector(this.target.x, this.target.y),      angle = this.position.angle(t);    let d_f_target = t.dist(this.position);      let f = new Vector().fromAngle(angle);       f.setMag(Util.map(Util.clamp(d_f_target,0,400), 0, 400, 0, this.topSpeed * 0.1));      this.addForce(f);         // Update&nbs
  


 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • HTML5 canvas如何绘制酷炫能量线条效果(附代码)

相关文章

  • dedecms5.7技术:“更新数据库archives表时出错,请检查
  • PHP常用函数之根据生日计算年龄功能示例
  • Linux下正确开启关闭redis的命令是什么
  • SyntaxHighlighter 去掉右侧滚动条的方法
  • CentOS7如何使用yum安装PHP7.3
  • 你知道Golang怎么封装PHP常用函数吗!
  • 一分钟学会PHP中关于封装验证码(下)
  • 详解Angular中的NgModule(模块)
  • PHP中fopen()函数的使用(附代码示例)
  • 浅谈小程序跨页面之间通信的几种方式

文章分类

  • dedecms
  • ecshop
  • z-blog
  • UcHome
  • UCenter
  • drupal
  • WordPress
  • 帝国cms
  • phpcms
  • 动易cms
  • phpwind
  • discuz
  • 科汛cms
  • 风讯cms
  • 建站教程
  • 运营技巧

最近更新的内容

    • 如何将label标签与input标签进行绑定
    • Illustrator绘制动感绚丽的广告背景
    • 最简单的WordPress手动输入页号并跳转翻页的方法
    • Photoshop制作逼真复古效果的黑胶唱片
    • Thinkphp自带分页类样式转Bootstrap分页样式
    • 教你怎么使用shell脚本实现服务器快速设置
    • 手把手教你用PHP完成一个分布式事务TCC
    • PHP采集插件QueryList实践教学
    • Illustrator绘制超酷效果的立体字教程
    • PhotoShop制作逼真的补丁文字效果的教程

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有