
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
mskalign-canvas
Advanced tools
基于 NURBS 曲线的脊椎模拟系统,采用面向对象设计,便于在其他项目中集成和使用。
<!-- 引入 verb-nurbs 库 -->
<script src="https://unpkg.com/verb-nurbs"></script>
<!-- 引入脊椎系统库 -->
<script src="spine-system.js"></script>
<canvas id="spineCanvas" width="400" height="600"></canvas>
// 脊椎点数据:[x, y] 坐标数组
const spineData = [
[200, 50],
[201, 70],
[202, 90],
[203, 110],
[204, 130],
[205, 150],
[206, 170],
[207, 190],
[208, 210],
[209, 230],
];
// 获取canvas元素
const canvas = document.getElementById("spineCanvas");
// 创建脊椎系统实例
const spineSystem = new SpineSystem(canvas, spineData, {
influence: 1.5, // 影响强度
curveDegree: 2, // 曲线次数
smoothness: 0.3, // 平滑度
influenceRange: 4, // 影响范围
showGrid: true, // 显示网格
});
// 渲染系统
spineSystem.render();
主要的脊椎系统类,协调所有组件的工作。
new SpineSystem(canvas, initialData, options);
canvas: HTML Canvas 元素initialData: 初始脊椎点数据,格式为 [[x1, y1], [x2, y2], ...]options: 配置选项对象const options = {
influence: 1.5, // 影响强度 (0.1 - 2.5)
curveDegree: 2, // 曲线次数 (2 - 5)
smoothness: 0.3, // 平滑度 (0.1 - 2.0)
influenceRange: 4, // 影响范围 (3 - 12)
showGrid: true, // 显示网格
};
// 更新配置
spineSystem.updateConfig(newConfig);
// 重置到初始状态
spineSystem.reset();
// 获取当前点位置
const points = spineSystem.getPoints();
// 获取原始点位置
const originalPoints = spineSystem.getOriginalPoints();
// 导出当前状态
const state = spineSystem.exportState();
// 导入状态
spineSystem.importState(state);
// 手动渲染
spineSystem.render();
// 销毁实例
spineSystem.destroy();
表示脊椎上的一个点。
point.x, point.y; // 当前坐标
point.originalX, point.originalY; // 原始坐标
point.index; // 点的索引
point.isEndPoint; // 是否为端点
point.isHovered; // 是否被悬停
point.isDragged; // 是否被拖拽
point.influenceState; // 影响状态:'normal' | 'influenced' | 'lightlyFollowing'
// 重置到原始位置
point.reset();
// 计算到指定坐标的距离
const distance = point.distanceTo(x, y);
// 获取点的颜色
const color = point.getColor();
// 获取点的半径
const radius = point.getRadius();
处理脊椎的物理约束和影响计算。
// 应用物理约束
physics.applyConstraints(points, smoothness);
// 应用影响效果
physics.applyInfluence(points, dragIndex, dragOffset, config);
// 计算三点间的角度
const angle = physics.calculateAngle(p1, p2, p3);
负责所有的绘制工作。
// 清空画布
renderer.clear();
// 绘制网格
renderer.drawGrid();
// 绘制NURBS曲线
renderer.drawNurbsCurve(curve, smoothness);
// 绘制连接线
renderer.drawConnectionLines(points);
// 绘制脊椎点
renderer.drawPoints(points);
// 绘制悬停信息
renderer.drawHoverInfo(point, mouseX, mouseY);
处理鼠标交互逻辑。
// 获取鼠标位置
const pos = interaction.getMousePosition();
// 获取悬停的点
const hoveredPoint = interaction.getHoveredPoint();
const spineSystem = new SpineSystem(canvas, spineData);
spineSystem.render();
// 监听滑块变化
document.getElementById("influenceSlider").addEventListener("input", (e) => {
spineSystem.updateConfig({ influence: parseFloat(e.target.value) });
});
// 保存状态
const currentState = spineSystem.exportState();
localStorage.setItem("spineState", JSON.stringify(currentState));
// 恢复状态
const savedState = JSON.parse(localStorage.getItem("spineState"));
spineSystem.importState(savedState);
// 创建多个独立的脊椎系统
const spineSystem1 = new SpineSystem(canvas1, spineData1, config1);
const spineSystem2 = new SpineSystem(canvas2, spineData2, config2);
// 各自独立运行
spineSystem1.render();
spineSystem2.render();
// 继承并扩展物理系统
class CustomSpinePhysics extends SpinePhysics {
applyConstraints(points, smoothness) {
// 先应用基础约束
super.applyConstraints(points, smoothness);
// 添加自定义约束
this.applyCustomConstraints(points);
}
applyCustomConstraints(points) {
// 自定义约束逻辑
}
}
// 使用自定义物理系统
const customSpineSystem = new SpineSystem(canvas, spineData);
customSpineSystem.physics = new CustomSpinePhysics();
// 继承并扩展渲染器
class CustomSpineRenderer extends SpineRenderer {
drawPoints(points) {
// 先绘制基础点
super.drawPoints(points);
// 添加自定义效果
this.drawCustomEffects(points);
}
drawCustomEffects(points) {
// 自定义绘制逻辑
}
}
// 使用自定义渲染器
const customSpineSystem = new SpineSystem(canvas, spineData);
customSpineSystem.renderer = new CustomSpineRenderer(canvas);
// 可以通过覆盖交互处理方法来添加自定义事件
class CustomSpineInteraction extends SpineInteraction {
handleMouseDown(e) {
// 调用原始处理
super.handleMouseDown(e);
// 添加自定义逻辑
console.log("点击了脊椎点");
}
}
render() 方法destroy() 方法MIT License
欢迎提交 Issue 和 Pull Request 来改进这个库。
FAQs
一个用于图片标注的javascript库,基于canvas,简单轻量,支持矩形、多边形、点、折线、圆形。
The npm package mskalign-canvas receives a total of 77 weekly downloads. As such, mskalign-canvas popularity was classified as not popular.
We found that mskalign-canvas demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.