Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  8] [ 5]  / answers: 1 / hits: 16213  / 10 Years ago, mon, december 29, 2014, 12:00:00

Problem:



I am trying to use p5.js in my simple app, and including it thus:



<script src=static/js/p5.js> </script>


What I've tried:



If I put a debugger and look in the console, I do get the functions for p5Color (for ex) and others. And the script gets loaded on to the page fine. Except createCanvas doesn't auto-complete and when used in the page, throws above error.



Why? How can I work around this?


More From » p5.js

 Answers
16

p5.js won't load into global mode unless it sees setup() or draw() defined on the page.



Option 1 - force global mode. (Note that if you do this, createCanvas() won't do you much good in the console, since setup() will have already run on page load.)



<script src=static/js/p5.js> </script>
<script>
function setup() {
//...
}
</script>


Option 2 - use instance mode. (This is probably your best bet if you really want to use p5.js from the console.)



var s = function( sketch ) {
sketch.setup = function() {
sketch.createCanvas(700, 410);
//...
};
};
var myp5 = new p5(s);

[#68362] Wednesday, December 24, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
darennevina

Total Points: 422
Total Questions: 128
Total Answers: 105

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
;