根据文档无法在 PaperJs 中创建随机点

use*_*388 2 javascript canvas paperjs

我正在使用最新版本的 PaperJs,但是当我从其示例中运行以下代码时,输​​出为“NaN”。

window.onload = function () {
    paper.setup('myCanvas');
    with (paper) {
        // Create a point whose x is between 0 and 50,
        // and y is between 0 and 100
        var point = new Point(50, 100) * Point.random();

        console.log(point);
    }
}
Run Code Online (Sandbox Code Playgroud)

该代码在 sketch.paperjs.org 中在线运行,但当我通过上面或下面的代码在本地尝试时不起作用(也输出“NaN”):

// Make the paper scope global, by injecting it into window:
paper.install(window);
window.onload = function () {
    // Setup directly from canvas id:
    paper.setup('myCanvas');

    // Create a point whose x is between 0 and 50,
    // and y is between 0 and 100
    var point = new Point(50, 100) * Point.random();

    console.log(point);
}
Run Code Online (Sandbox Code Playgroud)

以下内容有效,我的所有其他 PaperJs 代码也有效;只是我似乎无法根据文档创建随机点。

console.log(new Point(50, 100), Point.random());
Run Code Online (Sandbox Code Playgroud)

输出:

Point {x: 50, y: 100} Point {x: 0.8624748098043336, y: 0.8705165661914955}
Run Code Online (Sandbox Code Playgroud)

文档:http://paperjs.org/tutorials/geometry/mathematical-operations/#random-values

art*_*.sw 5

您确定使用paper.js语言而不是javascript吗?

由于乘法运算符无法在 JavaScript 中重载,因此必须使用pointA.multiply(pointB);.