光栅.on不是函数- Paper.js



我似乎无法从我正在使用paper.js的项目中获得任何输出

似乎不能识别栅格。On作为一个函数,由于某种原因…有没有人可以帮助我,为什么错误被显示说不是一个功能?

我试过用几种不同的方式初始化paperscript(或者我认为我有-作为一个新手)。

任何帮助都将非常感激,在过去的3-4天里一直在尝试,没有运气,很多跟踪和错误,没有快乐…boooooo:"(

请参见下面的js fiddle:

js小提琴光栅。关于非函数

/*Paper JS Setup for working in CodePen */
/* ====================== *
*  0. Initiate Canvas    *
* ====================== */

// expose paperjs classes into global scope
paper.install(window);
// bind paper to the canvas
paper.setup('canvas');

// Only executed our code once the DOM is ready.
window.onload = function() {
// Get a reference to the canvas object
var canvas = document.getElementById('myCanvas');


// Create a raster item using the image tag with id='mona'
var raster = new Raster('mona');
// Hide the raster:
raster.visible = false;
// The size of our grid cells:
var gridSize = 12;
// Space the cells by 120%:
var spacing = 1.2;
// As the web is asynchronous, we need to wait for the raster to     load
// before we can perform any operation on its pixels.
raster.on('load', function() {
// Since the example image we're using is much too large,
// and therefore has way too many pixels, lets downsize it to
// 40 pixels wide and 30 pixels high:
raster.size = new Size(40, 30);
for (var y = 0; y < raster.height; y++) {
for(var x = 0; x < raster.width; x++) {
// Get the color of the pixel:
var color = raster.getPixel(x, y);
// Create a circle shaped path:
var path = new Path.Circle({
center: new Point(x, y) * gridSize,
radius: gridSize / 2 / spacing,
fillColor: 'black'
});
// Scale the path by the amount of gray in the pixel     color:
path.scale(1 - color.gray);
}
}
// Move the active layer to the center of the view, so all 
// the created paths in it appear centered.
project.activeLayer.position = view.center;
});
}

正如光栅文档中所解释的那样,您应该使用raster.onLoad属性:

raster.onLoad = function() {
console.log('The image has loaded.');
};

最新更新