先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7
深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Web前端全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上前端开发知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
如果你需要这些资料,可以添加V获取:vip1024c (备注前端)
正文
// [
// [ ‘mouseenter’, e => mouseIn = true ],
// [ ‘mouseleave’, e => (mouseIn = false, mouseDown = false) ],
// [ ‘mousemove’, e => (mouseIn = true, mouseMove = e.timeStamp) ],
// [ ‘mousedown’, e => (mouseIn = true, mouseDown = true) ],
// [ ‘mouseup’, e => mouseDown = false ],
// [ ‘touchstart’, e => mouseIn = true ],
// [ ‘touchend’, e => (mouseIn = false, mouseDown = false) ],
// [ ‘touchcancel’, e => (mouseIn = false, mouseDown = false) ],
// [ ‘touchmove’, e => (mouseIn = true, mouseMove = e.timeStamp) ]
// ].forEach(([ eventName, cb ]) => document.body.addEventListener(eventName, e => {
// updateMouse(e);
// cb(e);
// }));
canvas.addEventListener(‘mouseenter’, e => (updateMouse(e), mouseIn = true));
canvas.addEventListener(‘mouseleave’, e => (updateMouse(e), mouseIn = false, mouseDown = false));
canvas.addEventListener(‘mousemove’, e => (updateMouse(e), mouseIn = true, mouseMove = e.timeStamp));
canvas.addEventListener(‘mousedown’, e => (updateMouse(e), mouseIn = true, mouseDown = true));
canvas.addEventListener(‘mouseup’, e => (updateMouse(e), mouseDown = false));
canvas.addEventListener(‘touchstart’, e => (updateMouse(e), mouseIn = true));
canvas.addEventListener(‘touchend’, e => (updateMouse(e), mouseIn = false, mouseDown = false));
canvas.addEventListener(‘touchcancel’, e => (updateMouse(e), mouseIn = false, mouseDown = false));
canvas.addEventListener(‘touchmove’, e => (updateMouse(e), mouseIn = true));
window.addEventListener(‘resize’, _resizeCanvas);
window.addEventListener(‘load’, () => {
mousePos = createVector();
mousePosPrev = createVector();
Object.assign(
_canvasOptions,
_defaulCanvasOptions,
‘canvasOptions’ in window ? window.canvasOptions : {}
);
if(_canvasOptions.canvas === false) {
document.body.removeChild(canvas);
}
_resizeCanvas();
if(‘setup’ in window) {
window.setup();
}
frameCount = 0;
_anim = requestAnimationFrame(_draw);
});
function _draw(timestamp) {
frameCount++;
canvasFrameRate = 1000.0 / (timestamp - _lastCanvasTime);
_lastCanvasTime = timestamp;
ctx = _originalCtx;
_canvasOptions.autoClear && clear(null);
if(_canvasOptions.autoPushPop) {
push();
_canvasOptions.centered && (_canvasCurrentlyCentered = true) && translateCenter();
_canvasOptions.autoCompensate && compensateCanvas();
}
‘draw’ in window && window.draw(timestamp);
_canvasOptions.autoPushPop && pop();
_canvasCurrentlyCentered = false;
_anim = requestAnimationFrame(_draw);
}
function _resizeCanvas(specificCanvas) {
// if(_canvasOptions.width === null)
width = canvas.width = _canvasOptions.width !== null ? _canvasOptions.width : window.innerWidth;
height = canvas.height = _canvasOptions.height !== null ? _canvasOptions.height : window.innerHeight;
width_quarter = (width_half = width * HALF) * HALF;
height_quarter = (height_half = height * HALF) * HALF;
ctx.fillStyle = ‘hsl(0, 0%, 100%)’;
ctx.strokeStyle = ‘hsl(0, 0%, 100%)’;
if(‘onResize’ in window) {
window.onResize();
}
}
function clear(x, y, w, h) {
if(x !== undefined && typeof x === ‘number’) {
ctx.clearRect(x, y, w, h);
}
else if(_canvasOptions.centered && _canvasCurrentlyCentered/* && x !== null */) {
ctx.clearRect(-width_half, -height_half, width, height);
}
else {
ctx.clearRect(0, 0, width, height);
}
}
function background(a) {
push();
if(typeof a !== ‘number’) {
fillStyle(a);
}
if(_canvasOptions.centered && _canvasCurrentlyCentered) {
ctx.fillRect(-width_half, -height_half, width, height);
}
else {
ctx.fillRect(0, 0, width, height);
}
pop();
}
function globalAlpha(alpha = ctx.globalAlpha) {
return ctx.globalAlpha = alpha;
}
function fillStyle(…args) {
if(args.length === 1) {
let a = args[0];
if(typeof a === ‘string’ || a instanceof CanvasGradient || a instanceof CanvasPattern) {
ctx.fillStyle = args[0];
}
}
return ctx.fillStyle;
}
function lineWidth(w) {
if(typeof w === ‘number’) {
ctx.lineWidth = w;
}
return ctx.lineWidth;
}
// “butt” || “round” || “square”;
function lineCap(style = ‘butt’) {
ctx.lineCap = style;
}
// “bevel” || “round” || “miter”
function lineJoin(style) {
ctx.lineJoin = style;
}
function miterLimit(value = 10) {
ctx.miterLimit = value;
}
function strokeStyle(…args) {
if(args.length === 1) {
let a = args[0];
if(typeof a === ‘string’ || a instanceof CanvasGradient) {
ctx.strokeStyle = a;
}
}
else if(args.length === 2) {
strokeStyle(args[0]);
lineWidth(args[1]);
}
return ctx.strokeStyle;
}
function lerpRGB(…args) {
let r1 = 255;
let b1 = 255;
let g1 = 255;
let a1 = 1;
let r2 = 0;
let g2 = 0;
let b2 = 0;
let a2 = 1;
let t = 0.5;
if(args.length === 3) {
if(Array.isArray(args[0]) && Array.isArray(args[1])) {
return lerpRGB(…args[0], …args[1], args[2]);
}
[
{ r: r1 = 255, b: b1 = 255, g: g1 = 255, a: a1 = 1 },
{ r: r2 = 0, b: b2 = 0, g: g2 = 0, a: a2 = 1 },
t
] = args;
}
else if(args.length === 7) {
[
r1, g1, b1,
r2, g2, b2,
t
] = args;
}
else if(args.length === 9) {
[
r1, g1, b1, a1,
r2, g2, b2, a2,
t
] = args;
}
else if(args.length === 2 && Array.isArray(args[0])) {
if(args[0].length === 2) {
return lerpRGB(…args[0], args[1]);
}
// TODO: Allow (possibly weighted) lerping between n-count RGBs at specified positions
}
else {
return { r: 127.5, g: 127.5, b: 127.5, a: 1 };
}
let r = lerp(r1, r2, t);
let g = lerp(g1, g2, t);
let b = lerp(b1, b2, t);
let a = lerp(a1, a2, t);
return { r, g, b, a };
}
function hsl(hue, sat, light, alpha = 1) {
if(typeof hue !== ‘number’) {
if(Array.isArray(hue)) {
[ hue, sat, light, alpha = alpha ] = hue;
}
else if(‘h’ in hue) {
({ h: hue, s: sat, l: light, a: alpha = alpha } = hue);
}
}
hue = hue % 360;
if(hue < 0) {
hue += 360;
}
return hsl(${hue} ${sat}% ${light}% / ${alpha})
;
}
function parseHSL(input) {
if(typeof input !== ‘string’) {
return input;
}
let result = input.match(/hsla?(([\d.]+)\s*,?\s*([\d.]+)%\s*,?\s*([\d.]+)%\s*[/,]?\s*([\d.]*)?)/);
if(result) {
let [ i, h, s, l, a ] = result;
return { input, h, s, l, a };
}
return null;
}
function setHueHSL(input, val) {
if(val === undefined) return input;
let p = parseHSL(input);
p.h = val;
return hsl§;
}
function rotateHSL(input, amt = 90) {
if(amt === 0) return input;
let p = parseHSL(input);
p.h += amt;
return hsl§;
}
function saturateHSL(input, amt = 0.1) {
if(amt === 0) return input;
let p = parseHSL(input);
p.s *= 1 + amt;
return hsl§;
}
function lightenHSL(input, amt = 0.1) {
if(amt === 0) return input;
let p = parseHSL(input);
p.l *= 1 + amt;
return hsl§;
}
function rgb(r = 255, g = 255, b = 255, a = 1) {
if(typeof r !== ‘number’ && ‘r’ in r) {
({ r = 255, g = 255, b = 255, a = 1 } = r);
}
return rgba(${r}, ${g}, ${b}, ${a})
;
}
function fill(…args) {
if(args.length) {
fillStyle(…args);
}
ctx.fill();
}
function stroke(…args) {
if(args.length) {
strokeStyle(…args);
}
ctx.stroke();
}
function clip() {
ctx.clip();
}
function createLinearGradient(x1 = -100, y1 = -100, x2 = 100, y2 = 100) {
// if(typeof x1 !== ‘number’) {
// if(‘x’ in x1) {
// }
// }
return ctx.createLinearGradient(x1, y1, x2, y2);
}
function createRadialGradient(x1 = 0, y1 = 0, r1 = 0, x2 = 0, y2 = 0, r2 = 200) {
return ctx.createRadialGradient(x1, y1, r1, x2, y2, r2);
}
function drawImage(img, x = 0, y = 0, …args) {
ctx.drawImage(img, x, y, …args);
}
function strokeText(str = ‘Hello world’, x = 0, y = 0) {
ctx.strokeText(str, x, y);
}
function fillText(str = ‘Hello world’, x = 0, y = 0) {
ctx.fillText(str, x, y);
}
function strokeFillText(str = ‘Hello world’, x = 0, y = 0) {
strokeText(str, x, y);
fillText(str, x, y);
}
function fillStrokeText(str = ‘Hello world’, x = 0, y = 0) {
fillText(str, x, y);
strokeText(str, x, y);
}
function measureText(…args) {
return ctx.measureText(…args);
}
// ctx.textAlign = “left” || “right” || “center” || “start” || “end”;
function textAlign(str = ‘left’) {
ctx.textAlign = str;
}
// ctx.textBaseline = “top” || “hanging” || “middle” || “alphabetic” || “ideographic” || “bottom”;
function textBaseline(str = ‘left’) {
if(str === ‘center’) str = ‘middle’;
ctx.textBaseline = str;
}
function push() {
ctx.save();
}
function pop() {
ctx.restore();
}
function resetTransform() {
ctx.resetTransform();
}
function translate(x = 0, y = 0) {
if(typeof x === ‘number’) {
ctx.translate(x, y);
}
else if(‘x’ in x) {
ctx.translate(x.x, x.y);
}
}
function translateCenter(x = 0, y = 0) {
ctx.translate(width_half + x, height_half + y);
}
function rotate(rot, offsetX, offsetY) {
rot = rot % TAU;
if(offsetX === undefined) {
ctx.rotate(rot);
}
else if(typeof offsetX !== ‘number’) {
if(‘x’ in offsetX) {
ctx.translate(offsetX.x, offsetX.y);
ctx.rotate(rot);
ctx.translate(-offsetX.x, -offsetX.y);
}
}
else {
ctx.translate(offsetX, offsetY);
ctx.rotate(rot);
ctx.translate(-offsetX, -offsetY);
}
}
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;
最后
在面试前我花了三个月时间刷了很多大厂面试题,最近做了一个整理并分类,主要内容包括html,css,JavaScript,ES6,计算机网络,浏览器,工程化,模块化,Node.js,框架,数据结构,性能优化,项目等等。
包含了腾讯、字节跳动、小米、阿里、滴滴、美团、58、拼多多、360、新浪、搜狐等一线互联网公司面试被问到的题目,涵盖了初中级前端技术点。
-
HTML5新特性,语义化
-
浏览器的标准模式和怪异模式
-
xhtml和html的区别
-
使用data-的好处
-
meta标签
-
canvas
-
HTML废弃的标签
-
IE6 bug,和一些定位写法
-
css js放置位置和原因
-
什么是渐进式渲染
-
html模板语言
-
meta viewport原理
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注前端)
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
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;
最后
在面试前我花了三个月时间刷了很多大厂面试题,最近做了一个整理并分类,主要内容包括html,css,JavaScript,ES6,计算机网络,浏览器,工程化,模块化,Node.js,框架,数据结构,性能优化,项目等等。
包含了腾讯、字节跳动、小米、阿里、滴滴、美团、58、拼多多、360、新浪、搜狐等一线互联网公司面试被问到的题目,涵盖了初中级前端技术点。
-
HTML5新特性,语义化
-
浏览器的标准模式和怪异模式
-
xhtml和html的区别
-
使用data-的好处
-
meta标签
-
canvas
-
HTML废弃的标签
-
IE6 bug,和一些定位写法
-
css js放置位置和原因
-
什么是渐进式渲染
-
html模板语言
-
meta viewport原理
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注前端)
[外链图片转存中…(img-znOcj9Yo-1713422407969)]
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!