-
-
Notifications
You must be signed in to change notification settings - Fork 16
Instance Mode
Quinton Ashley edited this page Oct 18, 2024
·
7 revisions
q5 introduces a new "instance" mode that enables multiple sketches to run on one page. You can call the instance variable whatever you like.
This example shows how you can avoid prefacing every q5 function and variable with q.
by using a JS with statement.
let q = new Q5('instance');
with (q) {
q.setup = () => {
createCanvas(400, 400);
};
q.draw = () => {
background(100);
};
}
For backwards compatibility, q5 also supports p5's instance mode.
let sketch = (q) => {
with (q) {
q.setup = () => {
createCanvas(400, 400);
};
q.draw = () => {
background(100);
};
}
};
let q = new Q5(sketch);
We need your support! Donate via Patreon or GitHub Sponsors.