无法根据文档在 PaperJs 中创建随机点
Can't Create Random Point in PaperJs per Documentation
我使用的是最新版本的 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);
}
}
The code works online in 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);
}
以下有效,我的所有其他 PaperJs 代码也有效;只是我似乎无法根据文档创建随机点。
console.log(new Point(50, 100), Point.random());
输出:
Point {x: 50, y: 100} Point {x: 0.8624748098043336, y: 0.8705165661914955}
文档:http://paperjs.org/tutorials/geometry/mathematical-operations/#random-values
您确定您使用的是paper.js语言而不是javascript吗?
因为乘法运算符不能在javascript中重载,所以必须使用pointA.multiply(pointB);
.
我使用的是最新版本的 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);
}
}
The code works online in 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);
}
以下有效,我的所有其他 PaperJs 代码也有效;只是我似乎无法根据文档创建随机点。
console.log(new Point(50, 100), Point.random());
输出:
Point {x: 50, y: 100} Point {x: 0.8624748098043336, y: 0.8705165661914955}
文档:http://paperjs.org/tutorials/geometry/mathematical-operations/#random-values
您确定您使用的是paper.js语言而不是javascript吗?
因为乘法运算符不能在javascript中重载,所以必须使用pointA.multiply(pointB);
.