我正在尝试使用Processing.js创建一个草图。我的代码没有丢失任何错误,但我甚至无法显示画布。我不知道我做错了什么。请帮忙。
这是我的代码:
function sketchPad(processing) {
processing.size(300,300);
processing.strokeWeight(10);
processing.frameRate(30);
processing.background(100);
processing.stroke(300);
processing.smooth();
var x = processing.mouseX;
var prevX = 0;
var y = processing.mouseY;
var prevY = 0;
function drawLine() {
processing.line(prevX,x,prevY,y);
prevX = processing.mouseX;
prevY = processing.mouseY;
}
processing.draw = function() {
if (processing.mousePressed == true && processing.mouseX > 0) {
drawLine();
}
}
var canvas = document.getElementById('canvas1');
var processingInstance = new Processing(canvas, sketchPad);
}
此代码不会产生任何错误,但同时不会出现任何错误。想法?
答案 0 :(得分:1)
您没有看到画布,因为显示它的调用需要在sketchPad方法之外。
function sketchPad(processing) {
// Your code goes here...
}
var canvas = document.getElementById('canvas1');
var processingInstance = new Processing(canvas, sketchPad);