MCPcopy Create free account
hub / github.com/Xu22Web/tech-study-js / createRandomPath

Function createRandomPath

tech-study.js:2285–2307  ·  view source on GitHub ↗

* @description 生成随机路径 * @param start * @param end * @param steps * @returns

(start, end, steps)

Source from the content-addressed store, hash-verified

2283 * @returns
2284 */
2285function createRandomPath(start, end, steps) {
2286 // 最小水平增量
2287 const minDeltaX = (end.x - start.x) / steps;
2288 // 最大垂直增量
2289 const maxDeltaY = (end.y - start.y) / steps;
2290 const path = [];
2291 // 开始节点
2292 path.push(start);
2293 // 插入点
2294 for (let i = 0; i < steps; i++) {
2295 // 横坐标
2296 const x = path[i].x + Math.random() * 5 + minDeltaX;
2297 // 纵坐标
2298 const y = path[i].y +
2299 Math.random() * 5 * Math.pow(-1, ~~(Math.random() * 2 + 1)) +
2300 maxDeltaY;
2301 path.push({
2302 x,
2303 y,
2304 });
2305 }
2306 return path;
2307}
2308/**
2309 * @description 随机数字
2310 * @returns

Callers 1

handleSlideVerifyFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected