canvas新年快乐烟花绽放动画效果代码

代码语言:html

所属分类:动画

代码描述:canvas新年快乐烟花绽放动画效果代码

代码标签: canvas 新年 快乐 烟花 绽放 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  

  
  
<style>
body {
  background: #141414;
  color: white;
  margin: 0;
  overflow: hidden;
}
</style>


  
</head>

<body translate="no">
  <script>
  window.canvasOptions = {
  	// autoClear: false,
  	//- centered: true,
  };

</script>

      <script  >
      var _window$canvasOptions, _window$canvasOptions2, _window$canvasOptions3, _window$canvasOptions4;const { PI, abs, floor, ceil, round, sign, pow, min, max, atan2, sqrt, asin } = Math;
const HALF_PI = PI * 0.5;
const TAU = PI * 2;
const cos = a => Math.cos(a % TAU);
const sin = a => Math.sin(a % TAU);
const tan = Math.tan;
class _VecShared {
  constructor(x = 0, y = 0) {this.x = x;this.y = y;}

  get xy() {return [this.x, this.y];}
  get yx() {return [this.y, this.x];}

  div() {throw new Error('Not implemented');}

  magSq() {throw new Error('Not implemented');}
  mag() {return Math.sqrt(this.magSq());}
  normalize(knownMag = this.mag()) {return knownMag ? this.div(knownMag) : this;}
  setMag(newMag, knownMag) {return this.normalize(knownMag).mult(newMag);}
  limit(magLimit, knownMag = this.mag()) {if (knownMag > magLimit) this.setMag(magLimit);return this;}}

window._VecShared = _VecShared;
class Vec2 extends _VecShared {
  static is(v) {return v instanceof Vec2;}
  static isAlike(v) {return typeof v !== 'number' && (v instanceof Vec2 || v instanceof Vec3);}
  static fa(a, m = 1) {return new Vec2(Math.cos(a), Math.sin(a)).mult(m);}
  static fromIndex(i, width) {return new Vec2(i % width, floor(i / width));}
  static random(xMin, xMax, yMin, yMax) {
    if (Vec2.isAlike(xMin) && xMax === undefined) {
      [xMin, xMax, yMin, yMax] = [0, xMin.x, 0, xMin.y];
    } else
    if (Vec2.isAlike(xMin) && Vec2.isAlike(xMax)) {
      [xMin, xMax, yMin, yMax] = [xMin.x, xMax.x, xMin.y, xMax.y];
    } else
    {
      if (Vec2.isAlike(xMin)) [xMin, xMax, yMin, yMax] = [...xMin.xy, xMax, yMin];
      if (Vec2.isAlike(yMin)) [yMin, yMax] = [...yMin.xy];
    }
    return new Vec2(random(xMin, xMax), random(yMin, yMax));
  }
  static min(...args) {return args.flat().reduce((p, n) => p.min(n), new Vec2());}
  static max(...args) {return args.flat().reduce((p, n) => p.max(n), new Vec2());}

  constructor(x, y) {super(x, y);}

  copy() {return new Vec2(this.x, this.y);}
  get _() {return new Vec2(this.x, this.y);}

  pickXY() {return new Vec2(this.x, this.y);}

  set(x, y) {if (Vec2.isAlike(x)) ({ x, y } = x);[this.x, this.y] = [x, y];return this;}
  setX(x) {if (Vec2.isAlike(x)) ({ x } = x);this.x = x;return this;}
  setY(y) {if (Vec2.isAlike(y)) ({ y } = y);this.y = y;return this;}

  add(x, y = x) {if (Vec2.isAlike(x)) ({ x, y } = x);this.x += x;this.y += y;return this;}
  addX(x) {if (Vec2.isAlike(x)) ({ x } = x);this.x += x;return this;}
  addY(y) {if (Vec2.isAlike(y)) ({ y } = y);this.y += y;return this;}

  sub(x, y = x) {if (Vec2.isAlike(x)) ({ x, y } = x);this.x -= x;this.y -= y;return this;}
  subX(x) {if (Vec2.isAlike(x)) ({ x } = x);this.x -= x;return this;}
  subY(y) {if (Vec2.isAlike(y)) ({ y } = y);this.y -= y;return this;}

  mult(x, y = x) {if (Vec2.isAlike(x)) ({ x, y } = x);this.x *= x;this.y *= y;return this;}
  multX(x) {if (Vec2.isAlike(x)) ({ x } = x);this.x *= x;return this;}
  multY(y) {if (Vec2.isAlike(y)) ({ y } = y);this.y *.........完整代码请登录后点击上方下载按钮下载查看

网友评论0