We are about to switch to a new forum software. Until then we have removed the registration on this forum.
as in title. I tried to call more then once the
var myCanvas = createCanvas(600, 400); code but I only get
Warning: createCanvas more than once NOT recommended. Very unpredictable behavior may result.
error. How to do it?
From their explanation above, the code below should work.
But it doesn't seem to ignite itself at all! :-w
@GoToLoop your code works for me. could you include which version of the library you're using and your html code?
@nootropickint, you shouldn't call createCanvas more than once... but there are a couple options.
check out the link @GoToLoop posted. you can have two totally different instances of p5.js sketches running on one page. for example if you copied his code above and pasted it twice you would have two sketches. you could then modify both independently.
you could use p5.Graphics to substitute as a second canvas. by default the p5.Graphics object is hidden when you call createGraphics() but you can show it by doing something like this.
in the above example, note that you will need to include the p5.dom library to use the .show() command. alternatively, you could replace that last line with:
myGraphics.elt.style.display = 'block'
Never did any html! I just paste code in some editable function reference! ;;)
The Learn | Beyond the Canvas page provides a start with working with DOM elements; this is a way to get 'more' out of a canvas space, but, it's not specifically what you are looking for.
Another thing, not specifically responsive to what you are looking for, but, is related to getting 'more canvas in the same page' is to set your sketch up using windowWidth, windowHeight, and windowResized to maximize your canvas space within a webpage, assuming your application is suitable for the extra code required for dynamic scaling/redrawing of sketch elements.
@GoToLoop ah this is probably the problem then. the function reference boxes are modified special just for displaying little bits of code on the page there. they don't necessarily work exactly the same as running code in your own sketch in the IDE or browser, especially for more complicated functionality.