gpt4 book ai didi

javascript - Paper.js 在路径上使用多个 moveTo 命令

转载 作者:行者123 更新时间:2023-11-29 10:26:31 24 4
gpt4 key购买 nike

我正在尝试:

blue X

使用这段代码:

var p = new Path();
p.strokeColor = 'blue'
p.strokeWidth = 4

var size = 10
var o = new Point(100, 100)

p.moveTo (o.add ([-size, -size]))
p.lineTo (o.add ([size, size]))
p.moveTo (o.add ([size, -size]))
p.lineTo (o.add ([-size, size]))

但我得到的是:

blue broken X

显然第二个 moveTo() 被忽略了。我怎样才能让它发挥作用?我在 documentation 中找不到任何内容.

最佳答案

您的解决方案是使用 CompoundPath 而不是 Path 因为您打算处理一组路径。
path.moveTo documentation 中有相关线索:

On a normal empty Path, the point is simply added as the path’s first segment. If called on a CompoundPath, a new Path is created as a child and the point is added as its first segment.

这是一个sketch根据您的初始代码改编,演示解决方案。

var p = new CompoundPath();
p.strokeColor = 'blue';
p.strokeWidth = 4;

var size = 10;
var o = new Point(100, 100);

p.moveTo(o.add([-size, -size]));
p.lineTo(o.add([size, size]));
p.moveTo(o.add([size, -size]));
p.lineTo(o.add([-size, size]));

关于javascript - Paper.js 在路径上使用多个 moveTo 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57844888/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com