Jared
Jared

Reputation: 39877

Error: 'CanvasElement' is undefined

I get Error: 'CanvasElement' is undefined when trying to run the following code using the javascript port of processing.

var p = Processing(CanvasElement);
    p.size(100, 100);
    p.background(0);
    p.fill(255);
    p.ellipse(50, 50, 50, 50);

Any help with this would be appreciated.

Upvotes: 0

Views: 798

Answers (2)

Matthew Crumley
Matthew Crumley

Reputation: 102715

You need to have a canvas element somewhere on the page that you can select:

<canvas id="theCanvas" width="500" height="500"></canvas>

Then you can select the element however you want and pass it (or its ID) to the Processing function:

var p = Processing(document.getElementById("theCanvas")); // or Processing("theCanvas")
p.size(100, 100);
p.background(0);
p.fill(255);
p.ellipse(50, 50, 50, 50);

Upvotes: 2

Andrew Hare
Andrew Hare

Reputation: 351456

Where is CanvasElement defined? It sounds like the code you posted is executing before the code that defines CanvasElement.

Upvotes: 0

Related Questions