- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试复制陶工的轮子效果,用户可以单击轮子的一 block ,按住鼠标,然后将相对于轮子的中心创建一个圆圈。
就像这个人的演示一样:https://balazsdavid987.github.io/Pottery-Wheel/
但是我可以在这里看到发生的事情: http://p2-paperjs-dpayne5-dpayne589733.codeanyapp.com:3000/coloring/
相关代码如下:
var tool = new paper.Tool();
//array to hold all curves drawn from mousedrags
var allPaths = [];
var currPath;
var rotationPath;
//wheel center point, @center of canvas
var wheelCenter = new paper.Point(350,350);
//create the potters wheel
var wheel = new paper.Path.Circle({
center: wheelCenter,
radius: 300,
strokeColor: 'black',
strokeWidth: 5
});
//hold down to create a continous curve with respect to wheelCenter
tool.onMouseDown = function(event) {
currPath = new paper.Path();
currPath.strokeColor = cp.history[cp.history.length-1];
currPath.strokeWidth = 10;
currPath.add(event.point);
}
//creates a curve from the last position to the new position of mouse
tool.onMouseDrag = function(event) {
currPath.add(currPath.rotate(4, wheelCenter));
}
//add the curve to allPaths, which then gets animated in onFrame
tool.onMouseUp = function(event) {
allPaths.push(currPath);
}
paper.view.onFrame = function(event) {
for (var i = 0; i < allPaths.length; i++) {
allPaths[i].rotate(4, wheelCenter);
}
//testPath.rotate(3, wheelCenter);
}
paper.view.draw();
我不明白为什么 mouseDrag 会从我的鼠标单击的位置开始画一个圆圈,而且我已经被困在这个问题上有一段时间了。
任何帮助将不胜感激,谢谢!
最佳答案
除了 onMouseDrag
方法方面存在技术困难之外,我认为您应该改变解决问题的方法。
问题是,如果您依赖鼠标拖动事件(仅在鼠标移动时触发),您将无法通过保持鼠标静态来在滚轮上绘画(如引用演示中所示)。
因此,您最好跟踪鼠标位置(通过监听鼠标移动事件),并在每一帧上进行绘制,将最后一个鼠标位置添加到当前路径(当然仅在绘制时)。
胜过千言万语,这里是 sketch演示如何实现这一点。
// Create the wheel.
const wheel = new Path.Circle({
center: view.center,
radius: 300,
strokeColor: 'black',
strokeWidth: 3
});
// Create a group that will contain all the user drawn path.
// This will allow us to more easily rotate them together.
const paths = new Group();
// Init state variables.
let currentPath;
let drawing = false;
let lastMousePosition;
// On mouse down...
function onMouseDown(event) {
// ...start a new path.
currentPath = new Path({
segments: [event.point],
strokeColor: 'red',
strokeWidth: 2
});
// Add it to the paths group.
paths.addChild(currentPath);
// Mark state as drawing.
drawing = true;
}
// On mouse move...
function onMouseMove(event) {
// ...keep track of the mouse position, this will be used to add points to
// the current path on each frame.
lastMousePosition = event.point;
}
// On mouse up...
function onMouseUp(event) {
// ...improve performances by simplifying the path.
currentPath.simplify();
// Mark state as not drawing.
drawing = false;
}
// On each frame...
function onFrame(event) {
// ...rotate paths around the wheel center.
paths.rotate(4, wheel.position);
// If we are currently drawing...
if (drawing) {
// ...add the last mouse position to the current path.
currentPath.add(lastMousePosition);
}
}
关于javascript - PaperJS 在 mouseDown 上创建圆圈时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57023457/
我一直试图弄清楚如何在 paperjs 中使用 onMouseDrag 和 onMouseDown 进行平移/缩放。 我看到的唯一引用是在 coffescript 中,并且不使用 paperjs 工具
我在一个 paperJS 项目上有多个图表。我想展示一个适合盒子的较小版本。说 500px X 350px。现在我怎样才能放大或缩小以最好的方式适合图表。 最佳答案 您可以缩放项目组以使其适合给定的框
如何使用 PaperJS 淡入/淡出光栅(图像)?目前我正在使用以下笨拙的函数来处理 1 个栅格(代码已简化): var img = new Raster('test.jpg'); img.opaci
我在一个 paperJS 项目上有多个图表。我想展示一个适合盒子的较小版本。说 500px X 350px。现在我怎样才能放大或缩小以最好的方式适合图表。 最佳答案 您可以缩放项目组以使其适合给定的框
如何处理大写或选项的 shift + 键? a可以是任何键,如 1或 !/或 ? 或 h或 shift + h 得到大写的 H。 我正在尝试使用 Paper.js 构建 WYSIWYG。 当我双击文本
使用Paperjs: 尝试在 myapp.js 中创建一个类: class Petal { constructor(index, x, y, diameter, round) { th
抱歉,这个问题考虑不周。我的意思是:我有 2 个点组成一个线段。然后我想将一个线段放置在与第一个线段成 x 度的 Angular 处。我该如何计算第三个点的位置? 基本上就是这个图: Diagram
我正在使用 paperjs,当用户绘制一条线时,我希望它在穿过之前绘制的线时停止。这是我当前的测试代码: tool.minDistance = 1; var path; var drawing = f
在使用 Paperjs 时,有一些奇怪的行为,我试图分别用 7 个点来弯曲一条线 - 一次效果很好,但是当尝试使链接超调并返回到 3 个不同的点时(以创建反弹效果) ) 好像不打球。在第二个 if 语
我已经使用 paperJS 创建了一个圆圈,现在我将为创建的圆圈应用撤消选项。那么如何将 Point {x: 537, y: 157}(这是 paperjs 中的 event.point)保存到数组中
如何对使用 onMouseDrag 绘制的圆应用拖放操作。 Look at the fiddle 最佳答案 Here is a fiddle带有拖放的粗略演示。通常,鼠标工具有两种模式;绘图和拖动。
我们已将 mouseMove/mouseEnter/mouseLeave 事件附加到形状/线条等,但我们正在寻找一种方法允许 paperjs 在鼠标靠近项目时触发这些事件(不一定要在它们之上触发)事件
here 中显示的示例显示如何在 Paperjs 中沿路径移动对象,但如何沿路径正确旋转对象? 在上面链接中显示的示例中,人们建议使用圆圈作为示例。但是一旦变成矩形 new Path.Rectangl
Paper.js 出现很多问题。在 Udemy 上参加 Colt Steele 的 Web 开发人员训练营。我在第 19 节。目前正在尝试制作 Patatap 克隆。
在 paperjs 中可以使用鼠标事件灵活地创建和操作复杂的形状。我正在从事的项目在台式机/笔记本电脑上看起来不错。但是,我也想通过捏合和缩放等触摸事件来进行形状操作。在 paperjs 中是否可以使
我已经成功实现了基于 this example 的缩放功能 zoom: function(delta, point){ if (!delta) return; var
我试图在 paperjs 中从另一个多边形中排除 1 个多边形,但似乎不知道如何做到这一点。 var base_points = [[50,50],[100,50],[125,10]]; var cl
在 http://paperjs.org/examples/chain/在源代码第 16 行你可以看到: var start = view.center / [10, 1]; 我假设这是某种二维向量除
我正在制作一个 paperjs 应用程序,其中有圆圈,每个圆圈都可以自由移动。一些圆通过线相互连接,这会导致圆彼此更靠近——即,线模拟圆之间的松紧带。然而,圆圈不允许重叠,所以我想进行某种碰撞排斥。目
我编写了这个脚本,当我移动 slider 时,方 block 应该立即调整大小。他们不知道。这需要几秒钟。有什么想法吗? 这是我的代码的链接:code on github gist 。 。为什么会延迟
我是一名优秀的程序员,十分优秀!