PDF / SVG libraries - rectMode(CENTER) not working

Hi there

So I’ve got a project, I go to export the files, all works as expected except for the rectangles which are now in the wrong positions. Same error with PDF and SVG libraries.

Is this a known issue with rectMode(CENTER)?

Does anyone have a workaround for this aside from me repositioning every rectangular element?

Thanks :slight_smile:

I ended up translating all my rectangle positions. Got the output I need now. Weird I couldn’t find any mention of this rectMode() thing online. :man_shrugging:

1 Like

Hi,

Look at the following examples, they work perfectly fine :wink: :

→ Export to PDF

import processing.pdf.*;

void setup() {
  size(400, 400, PDF, "output.pdf");
}

void draw() {
  rectMode(CENTER);
  rect(width / 2, height / 2, 100, 100);
  
  exit();
}

Capture d’écran de 2021-02-17 15-23-03


→ Export to SVG

import processing.svg.*;

void setup() {
  size(400, 400, SVG, "output.svg");
}

void draw() {
  rectMode(CENTER);
  rect(width / 2, height / 2, 100, 100);

  exit();
}

Capture d’écran de 2021-02-17 15-24-06

Thankyou for those. Tthey work perfectly, mine is all messed up :laughing:

My rectangles are also translated / rotated inside push/pop matrixes though, maybe that’s related?

Either way I found a route out of the madness :slight_smile:

1 Like

You are welcome! :wink:

Yes that’s probably the case, to rotate a rectangle on its center for example be careful to push and pop the matrix before drawing any other shapes that you don’t want to transform and use rectMode(CENTER) to center it.