canvas新年快乐烟花绽放动画效果代码
代码语言:html
所属分类:动画
代码描述: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 *= y;return this;} div(x, y = x) {if (Vec2.isAlike(x)) ({ x, y } = x);this.x /= x;this.y /= y;return this;} divX(x) {if (Vec2.isAlike(x)) ({ x } = x);this.x /= x;return this;} divY(y) {if (Vec2.isAlike(y)) ({ y } = y);this.y /= y;return this;} magSq() {return this.x * this.x + this.y * this.y;} heading() {return Math.atan2(this.y, this.x);} dist(v) {return v._.sub(this).mag();} rotate(a) {const [c, s] = [Math.cos(a), Math.sin(a)];[this.x, this.y] = [this.x * c - this.y * s, this.x * s + this.y * c];return this;} lerp(x, y, t) {if (Vec2.isAlike(x)) [x, y, t] = [x.x, x.y, y];[this.x, this.y] = [lerp(this.x, x, t), lerp(this.y, y, t)];return this;} dot(x, y) {if (Vec2.isAlike(x)) ({ x, y } = x);return this.x * x + this.y * y;} abs() {this.x = Math.abs(this.x);this.y = Math.abs(this.y);} min(x, y) {if (Vec2.isAlike(x)) ({ x, y } = x);[this.x, this.y] = [Math.min(this.x, x), Math.min(this.y, y)];return this;} max(x, y) {if (Vec2.isAlike(x)) ({ x, y } = x);[this.x, this.y] = [Math.max(this.x, x), Math.max(this.y, y)];return this;} halve() {return this.mult(0.5);} toIndex(width) {return this.y * width + this.x;} floor() {[this.x, this.y] = [floor(this.x), floor(this.y)];return this;} ceil() {[this.x, this.y] = [ceil(this.x), ceil(this.y)];return this;} round() {[this.x, this.y] = [round(this.x), round(this.y)];return this;} reflect(normal) {return this.sub(normal._.mult(this.dot(normal) * 2));}} window.Vec2 = Vec2; class Vec3 extends _VecShared { static is(v) {return v instanceof Vec3;} static fa(a, m) {return new Vec3(cos(a), sin(a), 0).mult(m);} static fromVec2(v2) {return new Vec3(v2.x, v2.y, 0);} constructor(x, y, z = 0) {super(x, y);this.z = z;} copy() {return new Vec3(this.x, this.y, this.z);} get _() {return new Vec3(this.x, this.y, this.z);} pickXY() {return new Vec3(this.x, this.y, 0);} pickYZ() {return new Vec3(0, this.y, this.z);} pickXZ() {return new Vec3(this.x, 0, this.z);} pickXYZ() {return new Vec3(this.x, this.y, this.z);} get yz() {return [this.y, this.z];} get zy() {return [this.z, this.y];} get xz() {return [this.x, this.z];} get zx() {return [this.z, this.x];} get xyz() {return [this.x, this.y, this.z];} get xzy() {return [this.x, this.z, this.y];} get yxz() {return [this.y, this.x, this.........完整代码请登录后点击上方下载按钮下载查看
网友评论0