【问题标题】:Cannot read property 'add' of null无法读取 null 的属性“添加”
【发布时间】:2021-02-01 22:55:18
【问题描述】:

您好,我在这里的编程有问题,即使绘制了形状也会出错,但我可以看到它;不太正确sketch

var circle= new Path.Circle({
    radius: 100,
    position: [200,200]
})

splat= new Path()
splat.fillColor= 'pink'
var count= 20
var length= circle.length
for(var i = 0; i <= count + 1; i++){
    var offset= i / count * length
    const normal = i === 0 || i === count
            ? new Point(0, 0)
            : circle.getNormalAt(offset) * (Math.random() * 50);
        const point = circle.getPointAt(offset).add(i % 2 == 0 ? normal
            : -normal);
            console.log(point)
            splat.add(point)
            splat.smooth({ type: 'catmull-rom', factor: 0.5 });
}


提前致谢

【问题讨论】:

    标签: paperjs


    【解决方案1】:

    您的 for 循环停止条件错误: i &lt;= count + 1 应该是:

    • i &lt; count + 1
    • i &lt;= count

    否则当i等于count + 1时,offset值大于length值,circle.getPointAt(offset)返回null。

    【讨论】:

    • 啊!谢谢你。我试图用'splat.closed = true'关闭路径,但似乎第一个点和最后一个点总是在一个点上而不是平滑的?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-29
    • 2021-12-21
    • 2016-11-24
    • 2012-04-29
    相关资源
    最近更新 更多