-
Hello! I'm trying to resize the p5 canvas when the user resizes the browser window. There is this function What I have so far that's not working: "use client"
import {P5CanvasInstance, ReactP5Wrapper } from "@p5-wrapper/react";
function setup(p5 : P5CanvasInstance) {
return () => {
p5.createCanvas(p5.windowWidth, p5.windowHeight, p5.WEBGL);
};
}
function draw(p5: P5CanvasInstance) {
return () => {
p5.background(250);
p5.normalMaterial();
p5.push();
p5.rotateZ(p5.frameCount * 0.01);
p5.rotateX(p5.frameCount * 0.01);
p5.rotateY(p5.frameCount * 0.01);
p5.plane(100);
p5.pop();
};
}
function windowResized(p5: P5CanvasInstance) {
p5.resizeCanvas(p5.windowWidth, p5.windowHeight)
}
function sketch(p5: P5CanvasInstance) {
p5.setup = setup(p5);
p5.draw = draw(p5);
p5.windowResized = windowResized(p5);
}
export default function Sketch() {
return <ReactP5Wrapper sketch={sketch} />;
} |
Beta Was this translation helpful? Give feedback.
Answered by
jamesrweb
Mar 31, 2024
Replies: 1 comment 2 replies
-
Try wrapping the body of |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
hanhanxue
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Try wrapping the body of
windowResized
in an anonymous function like the others.