Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can this be used only to save the image in svg but still render it with canvas #257

Open
romain-granai opened this issue Mar 13, 2024 · 1 comment

Comments

@romain-granai
Copy link

romain-granai commented Mar 13, 2024

As stated in the documentation, the svg rendering is slower, especialy with a lot of elements, is there a way to keep the rendering with canvas and still exporting in svg? Even if exporting is a little bit slower (time to convert the drawing into a svg), that's not really a problem, but it's way too slow on the rendering side and makes the app sometime unresponsive.

Thank you

@nkymut
Copy link

nkymut commented Mar 22, 2024

You can use the createGraphics() to create p5.Graphic objects for P2D and SVG renderers.
Then, use the P2D instance for drawing on the canvas and the SVG instance for exporting.

let pg;
let svgWriter;

function setup() {
  createCanvas(400, 400);
  pg = createGraphics(width,height); //P2D
  svgWriter = createGraphics(width,height,SVG);
}

function drawSomething(pgInstance){
  pgInstance.fill(0);
  pgInstance.rect(100,100,200,200);
}

function draw() {
  background(220);
  drawSomething(pg);
  translate(width/2,height/2);
  rotate(frameCount/8);
  imageMode(CENTER);
  image(pg,0,0);
}

function mousePressed(){
  print("export svg")
  drawSomething(svgWriter);
  svgWriter.save("svgTest.svg");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants