Pg graphics window is always square, even if main window size is rectangular

PFont font;
PGraphics pg;

void setup() {
  size(400, 600, P2D);
  font = createFont("helvetica_bold.otf", 30);
  pg = createGraphics(1000, 1000, P2D);
  //pg = createGraphics(400, 600, P2D); //or the same size as the size of window, same error: shows square area

void draw() {

  //bellow i used some pg graphics text animation code, which i found on the web
  pg.translate(width/2, height/2+100);
  pg.textAlign(CENTER, CENTER);
  pg.text("Test text", 0, 0);

  int tilesX = 16;
  int tilesY = 16;

  int tileW = int(width/tilesX);
  int tileH = int(width/tilesY);

  for (int y = 0; y < tilesY; y++) {
    for (int x = 0; x < tilesX; x++) {

      // WARP
      int wave = int(sin(frameCount * 0.4 + ( x * y ) * 0.2) * 15); 

      // SOURCE
      int sx = x*tileW + wave;
      int sy = y*tileH;
      int sw = tileW;
      int sh = tileH;

      int dx = x*tileW;
      int dy = y*tileH;
      int dw = tileW;
      int dh = tileH;
      copy(pg, sx, sy, sw, sh, dx, dy, dw, dh);


the text is clipped by that square space and therefore i can’t place it on the bottom of my work. i’ve colored the pg graphics background in grey. it’s size is set to be the same (or even bigger than the window size, no difference, same error) as the windows size, but it’s limited to a square. and i don’t know why. if someone can help me, i would be very grateful.

I think is at dx dy dw dh

copy(pg, sx, sy, sw, sh, dx, dy, dw, dh);

if do
copy(pg, sx, sy, sw, sh, 0, 0, width, height);

the pg shows over the whole sketch’s screen

1 Like

thank you very much! i tried to replace that variables, but it messed up the text itself. but your answer gave me a hint. so i looked at the values of tileH (dh = tileH) and noticed that it was linked to width… like tileW. changed it to height and everything fixed! you made my day, thank you a lot!

  int tileW = int(width/tilesX);
  int tileH = int(width/tilesY);

  int tileW = int(width/tilesX);
  int tileH = int(height/tilesY);

1 Like