【Html + Js + CSS——电流壁纸(1)

}

function scale(x = 1, y = x) {

ctx.scale(x, y);

}

function shearX(rad) {

ctx.transform(1, 0, tan(rad), 1, 0, 0);

}

function shearY(rad) {

ctx.transform(1, tan(rad), 0, 1, 0, 0);

}

function compensateCanvas() {

let offX = 0;

let offY = 0;

if(width % 2) offX += 0.5;

if(height % 2) offY += 0.5;

if(offX || offY) {

translate(offX, offY);

}

}

const compOper = {

default: ‘source-over’, sourceOver: ‘source-over’, sourceIn: ‘source-in’,

sourceOut: ‘source-out’, sourceAtop: ‘source-atop’, destinationOver: ‘destination-over’,

destinationIn: ‘destination-in’, destinationOut: ‘destination-out’, destinationAtop: ‘destination-atop’,

lighter: ‘lighter’, copy: ‘copy’, xor: ‘xor’,

multiply: ‘multiply’, screen: ‘screen’, overlay: ‘overlay’,

darken: ‘darken’, lighten: ‘lighten’, colorDodge: ‘color-dodge’,

colorBurn: ‘color-burn’, hardLight: ‘hard-light’, softLight: ‘soft-light’,

difference: ‘difference’, exclusion: ‘exclusion’, hue: ‘hue’,

saturation: ‘saturation’, color: ‘color’, luminosity: ‘luminosity’,

source: {

over: ‘source-over’, in: ‘source-in’, out: ‘source-out’,

atop: ‘source-atop’

},

destination: {

over: ‘destination-over’, in: ‘destination-in’, out: ‘destination-out’,

atop: ‘destination-atop’

},

light: {

hard: ‘hard-light’, soft: ‘soft-light’

}

};

function compositeOperation(type = compOper.default) { // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation

ctx.globalCompositeOperation = type;

}

// const filters = [

// [ ‘url’, [ ‘url’ ] ],

// [ ‘blur’, [ ‘length’ ] ],

// [ ‘brightness’, [ ‘percentage’ ] ],

// [ ‘contrast’, [ ‘percentage’ ] ]

// ];

function filter(filterFuncs = ‘none’) {

ctx.filter = filterFuncs;

}

function beginPath() {

ctx.beginPath();

}

function moveTo(x, y) {

if(typeof x === ‘number’) {

ctx.moveTo(x, y);

}

else if(‘x’ in x) {

ctx.moveTo(x.x, x.y);

}

}

function lineTo(x, y) {

if(typeof x === ‘number’) {

ctx.lineTo(x, y);

}

else if(‘x’ in x) {

ctx.lineTo(x.x, x.y);

}

}

function quadraticCurveTo(cpX, cpY, x, y) {

// ctx.quadraticCurveTo(cpX, cpY, x, y);

let a = [];

let b = [];

if(typeof cpX === ‘number’) {

a = [ cpX, cpY ];

if(typeof x === ‘number’) {

b = [ x, y ];

}

else if(‘x’ in x) {

b = x.xy;

}

}

else if(‘x’ in cpX) {

a = cpX.xy;

if(typeof cpY === ‘number’) {

b = [ cpY, x ];

}

else if(‘x’ in cpY) {

b = cpY.xy;

}

}

ctx.quadraticCurveTo(a[0], a[1], b[0], b[1]);

}

function bezierCurveTo(cp1X, cp1Y, cp2X, cp2Y, x, y) {

let a = [];

let b = [];

let c = [];

if(typeof cp1X === ‘number’) {

a = [ cp1X, cp1Y ];

if(typeof cp2X === ‘number’) {

b = [ cp2X, cp2Y ];

if(typeof x === ‘number’) {

c = [ x, y ];

}

else if(‘x’ in x) {

c = x.xy;

}

}

else if(‘x’ in cp2X) {

b = cp2X.xy;

if(typeof cp2Y === ‘number’) {

c = [ cp2Y, x ];

}

else if(‘x’ in cp2Y) {

c = cp2Y.xy;

}

}

}

else if(‘x’ in cp1X) {

a = cp1X.xy;

if(typeof cp1Y === ‘number’) {

b = [ cp1Y, cp2X ];

if(typeof cp2Y === ‘number’) {

c = [ cp2Y, x ];

}

else if(‘x’ in cp2Y) {

c = cp2Y.xy;

}

}

else if(‘x’ in cp1Y) {

b = cp1Y.xy;

if(typeof cp2X === ‘number’) {

c = [ cp2X, cp2Y ];

}

else if(‘x’ in cp2X) {

c = cp2X.xy;

}

}

}

ctx.bezierCurveTo(a[0], a[1], b[0], b[1], c[0], c[1]);

}

function closePath() {

ctx.closePath();

}

function point(x = 0, y = 0, r = 0, g = 0, b = 0, a = 255, doPut_ = true) {

// let imgData = ctx.createImageData(1, 1);

// imgData.data[0] = r;

// imgData.data[1] = g;

// imgData.data[2] = b;

// imgData.data[3] = a;

// if(doPut_) {

// ctx.putImageData(imgData, x, y);

// }

// return imgData;

}

function line(x = 0, y = 0, x_ = 0, y_ = 0) {

if(typeof x === ‘number’) {

moveTo(x, y);

lineTo(x_, y_);

}

else if(‘x’ in x) {

moveTo(x);

lineTo(y, x_);

}

}

function vertices(…verts) {

if(verts.length === 0) return;

else if(verts.length === 1 && Array.isArray(verts[0])) {

verts = verts[0];

}

for(let i = 0; i < verts.length; i++) {

let n = verts[i];

let x = 0;

let y = 0;

if(Array.isArray(n)) {

([ x, y ] = n);

}

else if(n instanceof Vector || (‘x’ in n && ‘y’ in n)) {

({ x, y } = n);

}

lineTo(x, y);

}

}

function arcTo(x1 = 0, y1 = 0, x2 = 0, y2 = 0, radius = 50) {

ctx.arcTo(x1, y1, x2, y2, radius);

}

function rect(x = 0, y = 0, w = 10, h = w, r = 0) {

if(r > 0) {

moveTo(x + r, y);

arcTo(x + w, y, x + w, y + h, r);

arcTo(x + w, y + h, x, y + h, r);

arcTo(x, y + h, x, y, r);

arcTo(x, y, x + w, y, r);

closePath();

}

else {

ctx.rect(x, y, w, h);

}

}

function arc(x = 0, y = 0, radius = 50, startAngle = 0, endAngle = Math.PI * 2, anticlockwise = false) {

if(radius < 0) radius = 0;

ctx.arc(x, y, radius, startAngle, endAngle, anticlockwise);

}

function circle(x = 0, y = undefined, rX = 20, rY = undefined) {

if(typeof x !== ‘number’ && ‘x’ in x) {

if(y !== undefined) {

rX = y;

}

y = x.y;

x = x.x;

}

else if(y === undefined) {

y = 0;

}

if(typeof rX !== ‘number’ && ‘x’ in rX) {

rY = rX.y;

rX = rX.x;

}

ctx.moveTo(x + rX, y);

if(rY !== undefined) {

ellipse(x, y, rX, rY);

}

else {

if(rX < 0) rX = 0;

ctx.arc(x, y, rX, 0, TAU);

}

}

function ellipse(x = 0, y = 0, rX = 50, rY = 50, rot = 0, angStart = 0, angEnd = Math.PI * 2, antiCw = false) {

if(rX < 0) rX = 0;

if(rY < 0) rY = 0;

ctx.ellipse(x, y, rX, rY, rot, angStart, angEnd, antiCw);

}

function regularPolygon(sides, radius = 50, rotation = 0) {

let circumference = TAU * radius;

let count = min(sides, circumference);

for(let i = 0; i < count; i++) {

let t = i / count * TAU + rotation;

let x = cos(t) * radius;

let y = sin(t) * radius;

if(i === 0) {

ctx.moveTo(x, y);

}

else {

ctx.lineTo(x, y);

}

}

ctx.closePath();

}

function genRegularPolygon(sides = 3, radius = 50, rotation = 0) {

let iSizes = 1 / sides * TAU;

let data = {

sides,

radius,

rotation,

points: []

};

for(let i = 0; i < sides; i++) {

let t = i * iSizes + rotation;

let x = cos(t) * radius;

let y = sin(t) * radius;

let point = createVector(x, y);

Object.assign(point, { i, t });

data.points.push(point);

}

return data;

}

function getCodePenID() {

if(_codepenIDRegex.test(window.location.href)) {

return _codepenIDRegex.exec(window.location.href)[1];

}

else {

let metas = document.getElementsByTagName(‘link’);

for(let i = 0; i < metas.length; i++) {

let m = metas[i];

if(m.getAttribute(‘rel’) == ‘canonical’) {

let id = _codepenIDRegex.exec(m.getAttribute(‘href’));

if(id) {

return id[1];

}

}

}

}

}

function isPreviewEmbed() {

return location.href.includes(‘/fullcpgrid/’);

}

function loadImage(url) {

return new Promise((resolve, reject) => {

let img = new Image();

img.crossOrigin = ‘Anonymous’;

img.onload = () => resolve(img);

img.src = url;

});

}

loadImage.alca = function(urlPart) {

return loadImage(‘https://alca.tv/static/’ + urlPart);

};

loadImage.alca.pen = function(urlPart) {

return loadImage.alca(‘codepen/’ + urlPart);

};

loadImage.alca.pen._ = function(urlPart) {

return loadImage.alca.pen(pens/${getCodePenID()}/${urlPart});

};

function loadVideo(url) {

return new Promise((resolve, reject) => {

let vid = document.createElement(‘video’);

vid.crossOrigin = ‘anonymous’;

vid.onloadeddata = () => resolve(vid);

vid.preload = true;

vid.muted = true;

vid.src = url;

vid.load();

});

}

loadVideo.alca = function(urlPart) {

return loadVideo(‘https://alca.tv/static/’ + urlPart);

};

loadVideo.alca.pen = function(urlPart) {

return loadVideo.alca(‘codepen/’ + urlPart);

};

loadVideo.alca.pen._ = function(urlPart) {

return loadVideo.alca.pen(pens/${getCodePenID()}/${urlPart});

};

function loadData(url) {

return fetch(url);

}

loadData.alca = function(urlPart) {

return loadData(‘https://alca.tv/static/’ + urlPart);

};

function loadText(url) {

return loadData(url)

.then(res => res.text());

}

loadText.alca = function(urlPart) {

return loadText(‘https://alca.tv/static/’ + urlPart);

};

function loadJSON(url) {

return loadData(url)

.then(res => res.json());

}

loadJSON.alca = function(urlPart) {

return loadJSON(‘https://alca.tv/static/’ + urlPart);

};

function getImageData(img, …args) {

if(img instanceof Image) {

let canvas = document.createElement(‘canvas’);

let ctx = canvas.getContext(‘2d’);

Object.assign(canvas, { width: img.width, height: img.height });

ctx.drawImage(img, 0, 0);

let data;

if(args.length) {

data = ctx.getImageData(…args);

}

else {

data = ctx.getImageData(0, 0, img.width, img.height);

}

return Object.assign(data, { canvas, ctx });

}

else {

return ctx.getImageData(img, …args);

}

}

function xyToI(x, y, w, h) {

if(typeof x !== ‘number’ && ‘x’ in x) {

h = w;

w = y;

({ x, y } = x);

}

if(w === undefined) w = 1;

// if(h === undefined) h = Infinity;

return x + w * y;

}

function iToXY(i, w, h) {

return createVector(i % w, floor(i / w));

}

function random(low = 1, high = null) {

if(Array.isArray(low)) {

return low[floor(Math.random() * low.length)];

}

if(high === null) {

return Math.random() * low;

}

return Math.random() * (high - low) + low;

}

let _randomGaussianPrevious = false;

let _randomGaussianY2 = 0;

// https://github.com/processing/p5.js/blob/5a46133fdc3e8c42fda1c1888864cf499940d86d/src/math/random.js#L166

// Offset, deviation

function randomGaussian(mean = 0, sd = 1) {

let y1, x1, x2, w;

if(_randomGaussianPrevious) {

y1 = _randomGaussianY2;

_randomGaussianPrevious = false;

}

else {

do {

x1 = random(2) - 1;

x2 = random(2) - 1;

w = x1 * x1 + x2 * x2;

} while (w >= 1);

w = sqrt(-2 * log(w) / w);

y1 = x1 * w;

_randomGaussianY2 = x2 * w;

_randomGaussianPrevious = true;

}

return y1 * (sd || 1) + mean;

}

function map(n, a, b, c, d) {

return (n - a) * (d - c) / (b - a) + c;

}

function constrain(n, mn, mx) {

return max(mn, min(mx, n));

}

function lerp(start, stop, amt = 0.5) {

if(typeof start !== ‘number’) {

return Vector.lerp(start, stop, amt);

}

return amt * (stop - start) + start;

}

function _distSq(x1, y1, x2, y2) {

let _x = x2 - x1;

let _y = y2 - y1;

return _x * _x + _y * _y;

}

function distSq(x1, y1, x2, y2) {

if(x1 === undefined || y1 === undefined || x2 === undefined || y2 === undefined) {

return 0;

}

else if(typeof x1 === ‘number’) {

if(x1 === x1) {

return _distSq(x1, y1, x2, y2);

}

return 0;

}

else if(‘x’ in x1) {

return _distSq(x1.x, x1.y, y1.x, y1.y);

}

return 0;

}

function dist(x1, y1, x2, y2) {

let d = distSq(x1, y1, x2, y2);

if(d === 0) {

return 0;

}

return sqrt(d);

}

function cos(input, mult = null) {

let c = Math.cos(input % TAU);

if(mult === null) {

return c;

}

return c * mult;

}

function sin(input, mult = null) {

let s = Math.sin(input % TAU);

if(mult === null) {

return s;

}

return s * mult;

}

function createVector(x, y, z) {

return new Vector(x, y, z);

}

class Vector {

constructor(x = 0, y = 0, z = 0) {

this.x = x;

this.y = y;

this.z = z;

}

toString() {

let { x, y, z } = this;

return { x: ${x}, y: ${y}, z: ${z} };

}

static center() {

return createVector(width_half, height_half);

}

static from(v, …args) {

if(v === undefined) {

return createVector();

}

else if(Array.isArray(v)) {

return createVector(…v);

}

else if(typeof v === ‘object’) {

return createVector(v.x, v.y, v.z);

}

else if(typeof v === ‘number’) {

return createVector(v, …args);

}

}

static fromAngle(angle, mult = 1) {

let v = createVector(cos(angle), sin(angle));

if(mult !== 1) v.mult(mult);

return v;

}

static random2D(angle = true, mult = 1) {

let v;

if(angle === true) {

v = Vector.fromAngle(random(TAU));

}

else {

v = createVector(random(-1, 1), random(-1, 1));

}

if(typeof angle === ‘number’) {

v.mult(angle);

}

else if(mult !== 1) {

v.mult(mult);

}

return v;

}

static lerp(start, stop, amt = 0.5, apply = false) {

let x = start.x === stop.x ? start.x : lerp(start.x, stop.x, amt);

let y = start.y === stop.y ? start.y : lerp(start.y, stop.y, amt);

let z = start.z === undefined ? stop.z === undefined ? 0 : stop.z : start.z === stop.z ? start.z : lerp(start.z, stop.z, amt);

if(apply) {

return start.set(x, y, z);

}

return createVector(x, y, z);

}

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

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

get xz() { return [ this.x, this.z ]; }

get zx() { return [ this.z, this.x ]; }

get yz() { return [ this.y, this.z ]; }

get zy() { return [ this.z, this.y ]; }

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.z ]; }

get yzx() { return [ this.y, this.z, this.x ]; }

get zyx() { return [ this.z, this.y, this.x ]; }

get zxy() { return [ this.z, this.x, this.y ]; }

get xyObject() { return { x: this.x, y: this.y }; }

get xzObject() { return { x: this.x, z: this.z }; }

get yzObject() { return { y: this.y, z: this.z }; }

get xyzObject() { return { x: this.x, y: this.y, z: this.z }; }

copy() {

return createVector(this.x, this.y, this.z);

}

get _() {

return this.copy();

}

equals(vec) {

return this.x === vec.x && this.y === vec.y;

}

equals3D(vec = {}) {

return this.x === vec.x && this.y === vec.y && this.z === vec.z;

}

draw() {

point(this.x, this.y);

}

set(x = this.x, y = this.y, z = this.z) {

if(x instanceof Vector) {

this.x = x.x;

this.y = x.y;

this.z = x.z;

return this;

}

this.x = x;

this.y = y;

this.z = z;

return this;

}

setX(x = this.x) {

if(x instanceof Vector) {

this.x = x.x;

return this;

}

this.x = x;

return this;

}

setY(y = this.y) {

if(y instanceof Vector) {

this.y = y.y;

return this;

}

this.y = y;

return this;

}

setZ(z = this.z) {

if(z instanceof Vector) {

this.z = z.z;

return this;

}

this.z = z;

return this;

}

setXY(x = this.x, y = this.y) {

if(x instanceof Vector) {

this.x = x.x;

this.y = x.y;

return this;

}

this.x = x;

this.y = y;

return this;

}

setYZ(y = this.y, z = this.z) {

if(y instanceof Vector) {

this.y = y.y;

this.z = y.z;

return this;

}

this.y = y;

this.z = z;

return this;

}

setXZ(x = this.x, z = this.y) {

if(x instanceof Vector) {

this.x = x.x;

this.z = x.z;

return this;

}

this.x = x;

this.z = z;

return this;

}

setZX(…args) {

return this.setXZ(…args);

}

add(x = 0, y = x, z = 0) {

if(x instanceof Vector) {

this.x += x.x;

this.y += x.y;

this.z += x.z;

return this;

}

this.x += x;

this.y += y;

this.z += z;

return this;

}

addX(n = 0) {

if(n instanceof Vector) {

this.x += n.x;

return this;

}

this.x += n;

return this;

}

addY(n = 0) {

if(n instanceof Vector) {

this.y += n.y;

return this;

}

this.y += n;

return this;

}

addZ(n = 0) {

if(n instanceof Vector) {

this.z += n.z;

return this;

}

this.z += n;

return this;

}

sub(x = 0, y = x, z = 0) {

if(x instanceof Vector) {

this.x -= x.x;

this.y -= x.y;

this.z -= x.z;

return this;

}

this.x -= x;

this.y -= y;

this.z -= z;

return this;

}

subX(n = 0) {

if(n instanceof Vector) {

this.x -= n.x;

return this;

}

this.x -= n;

return this;

}

subY(n = 0) {

if(n instanceof Vector) {

this.y -= n.y;

return this;

}

this.y -= n;

return this;

}

subZ(n = 0) {

if(n instanceof Vector) {

this.z -= n.z;

return this;

}

this.z -= n;

return this;

}

mult(x = 1, y = x, z = x) {

if(x instanceof Vector) {

this.x *= x.x;

this.y *= x.y;

this.z *= x.z;

return this;

}

this.x *= x;

this.y *= y;

this.z *= z;

return this;

}

multX(n = 1) {

if(n instanceof Vector) {

this.x *= n.x;

return this;

}

this.x *= n;

return this;

}

multY(n = 1) {

if(n instanceof Vector) {

this.y *= n.y;

return this;

}

this.y *= n;

return this;

}

multZ(n = 1) {

if(n instanceof Vector) {

this.z *= n.z;

return this;

}

this.z *= n;

return this;

}

div(x = 1, y = x, z = x) {

if(x instanceof Vector) {

this.x /= x.x;

this.y /= x.y;

this.z /= x.z;

return this;

}

this.x /= x;

this.y /= y;

this.z /= z;

return this;

}

divX(n = 1) {

if(n instanceof Vector) {

this.x /= n.x;

return this;

}

this.x /= n;

return this;

}

divY(n = 1) {

if(n instanceof Vector) {

this.y /= n.y;

return this;

}

this.y /= n;

return this;

}

divZ(n = 1) {

if(n instanceof Vector) {

this.z /= n.z;

return this;

}

this.z /= n;

return this;

}

mod(x, y, z) {

if(x === undefined) return this;

else if(x instanceof Vector) {

this.x %= x.x;

this.y %= x.y;

this.z %= x.z;

return this;

}

this.x %= x;

this.y %= y === undefined ? x : y;

this.z %= z === undefined ? x : y;

return this;

}

// TODO: modX, modY, modZ

min(mX = this.x, mY = this.y, mZ = this.z) {

if(mX instanceof Vector) {

this.x = min(this.x, mX.x);

this.y = min(this.y, mX.y);

this.z = min(this.z, mX.z);

return this;

}

this.x = min(this.x, mX);

this.y = min(this.y, mY);

this.z = min(this.z, mZ);

return this;

}

max(mX = this.x, mY = this.y, mZ = this.z) {

if(mX instanceof Vector) {

this.x = max(this.x, mX.x);

this.y = max(this.y, mX.y);

this.z = max(this.z, mX.z);

return this;

}

this.x = max(this.x, mX);

this.y = max(this.y, mY);

this.z = max(this.z, mZ);

return this;

}

minX(n) {

this.x = min(this.x, n instanceof Vector ? n.x : n);

return this;

}

minY(n) {

this.y = min(this.y, n instanceof Vector ? n.y : n);

return this;

}

minZ(n) {

this.z = min(this.z, n instanceof Vector ? n.z : n);

return this;

}

maxX(n) {

this.x = max(this.x, n instanceof Vector ? n.x : n);

return this;

}

maxY(n) {

this.y = max(this.y, n instanceof Vector ? n.y : n);

return this;

}

maxZ(n) {

this.z = max(this.z, n instanceof Vector ? n.z : n);

return this;

}

heading() {

return atan2(this.y, this.x);

}

rotate(a = 0) {

// if(a === 0) {

// return this;

// }

// let newHeading = this.heading() + a;

// let mag = this.mag();

// return this.set(cos(newHeading), sin(newHeading)).mult(mag);

if(!a) {

return this;

}

const c = cos(a);

const s = sin(a);

const { x, y } = this;

this.x = x * c - y * s;

this.y = x * s + y * c;

return this;

}

rotateXY(a) {

let v = new Vector(this.x, this.y).rotate(a);

this.x = v.x;

this.y = v.y;

return this;

}

rotateYZ(a) {

let v = new Vector(this.y, this.z).rotate(a);

this.y = v.x;

this.z = v.y;

return this;

}

rotateZX(a) {

let v = new Vector(this.z, this.x).rotate(a);

this.z = v.x;

this.x = v.y;

return this;

}

magSq() {

return this.x * this.x + this.y * this.y;

}

magSq3D() {

return this.x * this.x + this.y * this.y + this.z * this.z;

}

mag() {

return Math.sqrt(this.magSq());

// return hypot(this.x, this.y);

}

mag3D() {

return Math.sqrt(this.magSq3D());

// return hypot(this.x, this.y);

}

normalize(mag = this.mag()) {

return mag === 0 ? this : this.div(mag);

}

normalize3D(mag = this.mag3D()) {

return mag === 0 ? this : this.div(mag);

}

setMag(mag) {

return this.normalize().mult(mag);

}

setMag3D(mag) {

return this.normalize3D().mult(mag);

}

limit(max) {

const magSq = this.magSq();

if(magSq > max * max) {

this.div(sqrt(magSq));

this.mult(max);

}

return this;

}

limit3D(max) {

const magSq = this.magSq3D();

if(magSq > max * max) {

this.div(sqrt(magSq));

this.mult(max);

}

return this;

}

dot(x = 0, y = 0) {

if(x instanceof Vector) {

return this.dot(x.x, x.y);

}

return this.x * x + this.y * y;

}

dot3D(x = 0, y = 0, z = 0) {

if(x instanceof Vector) {

return this.dot(x.x, x.y, x.z);

}

return this.x * x + this.y * y + this.z * z;

}

dist(x, y) {

if(x instanceof Vector) {

return x.copy().sub(this).mag();

}

else if(typeof x === ‘object’ && ‘x’ in x) {

({ x, y } = x);

}

return dist(this.x, this.y, x, y);

}

dist3D(v) {

return v.copy().sub(this).mag3D();

}

lerp(stop, amt) {

return Vector.lerp(this, stop, amt, true);

}

round() {

this.x = round(this.x);

this.y = round(this.y);

this.z = round(this.z);

return this;

}

floor() {

this.x = floor(this.x);

this.y = floor(this.y);

this.z = floor(this.z);

return this;

}

fastFloor() {

this.x = ~~this.x;

this.y = ~~this.y;

this.z = ~~this.z;

return this;

}

ceil() {

this.x = ceil(this.x);

this.y = ceil(this.y);

this.z = ceil(this.z);

return this;

}

}

// Robert Penner - http://gizma.com/easing/

// t: Current time

// b: Start value

// c: Change in value

// d: Duration

function linearTween /* simple linear tweening */ (t = 0.5, b = 0, c = 1, d = 1) { return c * t / d + b; }

function easeInQuad /* quadratic easing in */ (t = 0.5, b = 0, c = 1, d = 1) { t /= d; return c * t * t + b; }

function easeOutQuad /* quadratic easing out */ (t = 0.5, b = 0, c = 1, d = 1) { t /= d; return -c * t * (t - 2) + b; }

function easeInOutQuad /* quadratic easing in/out */ (t = 0.5, b = 0, c = 1, d = 1) { t /= d * 0.5; if(t < 1) return c * 0.5 * t * t + b; t–; return -c * 0.5 * (t * (t - 2) - 1) + b; }

function easeInCubic /* cubic easing in */ (t = 0.5, b = 0, c = 1, d = 1) { t /= d; return c * t * t * t + b; }

function easeOutCubic /* cubic easing out */ (t = 0.5, b = 0, c = 1, d = 1) { t /= d; t–; return c * (t * t * t + 1) + b; }

function easeInOutCubic /* cubic easing in/out */ (t = 0.5, b = 0, c = 1, d = 1) { t /= d * 0.5; if(t < 1) return c * 0.5 * t * t * t + b; t -= 2; return c * 0.5 * (t * t * t + 2) + b; }

function easeInQuart /* quartic easing in */ (t = 0.5, b = 0, c = 1, d = 1) { t /= d; return c * t * t * t * t + b; }

function easeOutQuart /* quartic easing out */ (t = 0.5, b = 0, c = 1, d = 1) { t /= d; t–; return -c * (t * t * t * t - 1) + b; }

function easeInOutQuart /* quartic easing in/out */ (t = 0.5, b = 0, c = 1, d = 1) { t /= d * 0.5; if(t < 1) return c * 0.5 * t * t * t * t + b; t -= 2; return -c * 0.5 * (t * t * t * t - 2) + b; }

function easeInQuint /* quintic easing in */ (t = 0.5, b = 0, c = 1, d = 1) { t /= d; return c * t * t * t * t * t + b; }

function easeOutQuint /* quintic easing out */ (t = 0.5, b = 0, c = 1, d = 1) { t /= d; t–; return c * (t * t * t * t * t + 1) + b; }

function easeInOutQuint /* quintic easing in/out */ (t = 0.5, b = 0, c = 1, d = 1) { t /= d * 0.5; if(t < 1) return c * 0.5 * t * t * t * t * t + b; t -= 2; return c * 0.5 * (t * t * t * t * t + 2) + b; }

function easeInSine /* sinusoidal easing in */ (t = 0.5, b = 0, c = 1, d = 1) { return -c * cos(t / d * HALF_PI) + c + b; }

function easeOutSine /* sinusoidal easing out */ (t = 0.5, b = 0, c = 1, d = 1) { return c * sin(t / d * HALF_PI) + b; }

function easeInOutSine /* sinusoidal easing in/out */ (t = 0.5, b = 0, c = 1, d = 1) { return -c * 0.5 * (cos(PI * t / d) - 1) + b; }

function easeInExpo /* exponential easing in */ (t = 0.5, b = 0, c = 1, d = 1) { return c * pow(2, 10 * (t / d - 1)) + b; }

function easeOutExpo /* exponential easing out */ (t = 0.5, b = 0, c = 1, d = 1) { return c * (-pow(2, -10 * t / d ) + 1) + b; }

function easeInOutExpo /* exponential easing in/out */ (t = 0.5, b = 0, c = 1, d = 1) { t /= d * 0.5; if(t < 1) return c * 0.5 * pow(2, 10 * (t - 1)) + b; t–; return c * 0.5 * (-pow(2, -10 * t) + 2) + b; }

function easeInCirc /* circular easing in */ (t = 0.5, b = 0, c = 1, d = 1) { t /= d; return -c * (sqrt(1 - t * t) - 1) + b; }

function easeOutCirc /* circular easing out */ (t = 0.5, b = 0, c = 1, d = 1) { t /= d; t–; return c * sqrt(1 - t * t) + b; }

function easeInOutCirc /* circular easing in/out */ (t = 0.5, b = 0, c = 1, d = 1) { t /= d * 0.5; if(t < 1) return -c * 0.5 * (sqrt(1 - t * t) - 1) + b; t -= 2; return c * 0.5 * (sqrt(1 - t * t) + 1) + b; }

const ease = {

linearTween,

easeInQuad, easeOutQuad, easeInOutQuad,

easeInCubic, easeOutCubic, easeInOutCubic,

easeInQuart, easeOutQuart, easeInOutQuart,

easeInQuint, easeOutQuint, easeInOutQuint,

easeInSine, easeOutSine, easeInOutSine,

easeInExpo, easeOutExpo, easeInOutExpo,

easeInCirc, easeOutCirc, easeInOutCirc,

in: { linear: linearTween, quad: easeInQuad, cubic: easeInCubic, quart: easeInQuart, quint: easeInQuint, sine: easeInSine, expo: easeInExpo, circ: easeInCirc },

out: { linear: linearTween, quad: easeOutQuad, cubic: easeOutCubic, quart: easeOutQuart, quint: easeOutQuint, sine: easeOutSine, expo: easeOutExpo, circ: easeOutCirc },

inOut: { linear: linearTween, quad: easeInOutQuad, cubic: easeInOutCubic, quart: easeInOutQuart, quint: easeInOutQuint, sine: easeInOutSine, expo: easeInOutExpo, circ: easeInOutCirc },

linear: Object.assign(linearTween,

{ in: linearTween, out: linearTween, inOut: linearTween }),

quad: { in: easeInQuad, out: easeOutQuad, inOut: easeInOutQuad },

cubic: { in: easeInCubic, out: easeOutCubic, inOut: easeInOutCubic },

quart: { in: easeInQuart, out: easeOutQuart, inOut: easeInOutQuart },

quint: { in: easeInQuint, out: easeOutQuint, inOut: easeInOutQuint },

sine: { in: easeInSine, out: easeOutSine, inOut: easeInOutSine },

expo: { in: easeInExpo, out: easeOutExpo, inOut: easeInOutExpo },

circ: { in: easeInCirc, out: easeOutCirc, inOut: easeInOutCirc }

};

function getTimeArray(timestamp = null) {

if(timestamp === null) {

timestamp = new Date();

}

else if(typeof timestamp === ‘string’ || typeof timestamp === ‘number’) {

let parsedTimestamp = Date.parse(timestamp);

if(!isNaN(parsedTimestamp)) {

timestamp = new Date(parsedTimestamp);

}

else {

throw new RangeError(‘Invalid Date’);

}

}

else if(!(timestamp instanceof Date)) {

throw new TypeError(‘Unsupported timestamp’);

最后

面试题文档来啦,内容很多,485页!

由于笔记的内容太多,没办法全部展示出来,下面只截取部分内容展示。

1111道Java工程师必问面试题

MyBatis 27题 + ZooKeeper 25题 + Dubbo 30题:

Elasticsearch 24 题 +Memcached + Redis 40题:

Spring 26 题+ 微服务 27题+ Linux 45题:

Java面试题合集:

easeInExpo, easeOutExpo, easeInOutExpo,

easeInCirc, easeOutCirc, easeInOutCirc,

in: { linear: linearTween, quad: easeInQuad, cubic: easeInCubic, quart: easeInQuart, quint: easeInQuint, sine: easeInSine, expo: easeInExpo, circ: easeInCirc },

out: { linear: linearTween, quad: easeOutQuad, cubic: easeOutCubic, quart: easeOutQuart, quint: easeOutQuint, sine: easeOutSine, expo: easeOutExpo, circ: easeOutCirc },

inOut: { linear: linearTween, quad: easeInOutQuad, cubic: easeInOutCubic, quart: easeInOutQuart, quint: easeInOutQuint, sine: easeInOutSine, expo: easeInOutExpo, circ: easeInOutCirc },

linear: Object.assign(linearTween,

{ in: linearTween, out: linearTween, inOut: linearTween }),

quad: { in: easeInQuad, out: easeOutQuad, inOut: easeInOutQuad },

cubic: { in: easeInCubic, out: easeOutCubic, inOut: easeInOutCubic },

quart: { in: easeInQuart, out: easeOutQuart, inOut: easeInOutQuart },

quint: { in: easeInQuint, out: easeOutQuint, inOut: easeInOutQuint },

sine: { in: easeInSine, out: easeOutSine, inOut: easeInOutSine },

expo: { in: easeInExpo, out: easeOutExpo, inOut: easeInOutExpo },

circ: { in: easeInCirc, out: easeOutCirc, inOut: easeInOutCirc }

};

function getTimeArray(timestamp = null) {

if(timestamp === null) {

timestamp = new Date();

}

else if(typeof timestamp === ‘string’ || typeof timestamp === ‘number’) {

let parsedTimestamp = Date.parse(timestamp);

if(!isNaN(parsedTimestamp)) {

timestamp = new Date(parsedTimestamp);

}

else {

throw new RangeError(‘Invalid Date’);

}

}

else if(!(timestamp instanceof Date)) {

throw new TypeError(‘Unsupported timestamp’);

最后

面试题文档来啦,内容很多,485页!

由于笔记的内容太多,没办法全部展示出来,下面只截取部分内容展示。

1111道Java工程师必问面试题

[外链图片转存中…(img-reRPWyc5-1714495542220)]

MyBatis 27题 + ZooKeeper 25题 + Dubbo 30题:

[外链图片转存中…(img-TNVtIdo6-1714495542221)]

Elasticsearch 24 题 +Memcached + Redis 40题:

[外链图片转存中…(img-0PYk8DWf-1714495542221)]

Spring 26 题+ 微服务 27题+ Linux 45题:

[外链图片转存中…(img-N8d237jj-1714495542222)]

Java面试题合集:

[外链图片转存中…(img-O8IcaAIU-1714495542222)]

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

  • 26
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值