javascript + HTML5画板

时间:2012-01-22 21:23:48

标签: javascript html5 processing processing.js

我正在尝试使用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);
}

此代码不会产生任何错误,但同时不会出现任何错误。想法?

1 个答案:

答案 0 :(得分:1)

您没有看到画布,因为显示它的调用需要在sketchPad方法之外。

function sketchPad(processing) {
    // Your code goes here...
}
var canvas = document.getElementById('canvas1');
var processingInstance = new Processing(canvas, sketchPad);