I’m working on a small project website where clients draw something and then they can click a button to send the canvas to the server, and then the server sends it back to other clients and the canvas image is set as their background.
What I haven’t figured out yet is how to put the canvas image in a variable to then load it in the background as follows:
// this code is not working but I think you get the idea. I save the canvas image in a variable
var canvas = createCanvas(500, 500)
// then I put the canvas in the background() function
background(canvas)
This is not exactly my code, but if you have some experience with sockets I think you will understand the code below:
const canvas = createCanvas(500,500);
// sendCanvas event below is when the server wants the canvas of this client, then emit sends the
// canvas in an event called getCanvas
socket.on('sendCanvas', () => {socket.emit('getCanvas', canvas));
// Canvas event is for getting the canvas from the server, then it sets the background as the canvas given by the server.
socket.on('Canvas', canvas => {background(canvas));
/* This is what I've already tried. I also tried saveCanvas but it didn't save it anywhere in the project
folder
*/
I know this may be very confusing, but I’m new to p5.js so feel free to ask any question regarding my code (which doesn’t work). also don’t worry about the socket.io part, it definitely works.