Problem with rotated PGraphics

I’ve spent a couple hours trying to make an MCVE of this but haven’t been able to replicate the problem. The main program is at 2k lines so I can’t post it here. I’ve been stuck on this for a while so really hoping someone has a hint.

I have a design I’m generating pictured here:
When I render this to the screen it looks fine.
When I render it to a PGraphic I’ve created and display it via image() it still looks fine, but when I do a rotate() before calling image() to render it to the screen, the lines end up distorted.
Here’s a zoom:

This doesn’t happen when I call rotate() and render it directly to the screen.

I thought this might be a problem with antialiasing being used once on the PGraphic and once when it was rendered via image(), so I tried noSmooth() on the PGraphic, and got different, but still broken results.
Here’s noSmooth() with no rotation:
And here it is with rotation:

I thought I found the answer when I came across this thread: offscreen PGraphics is ugly which suggests that the problem is antialiasing mixing my black pixels with transparent pixels, from the PGraphic, but drawing a background to my PGraphic as soon as I instantiate it doesn’t seem to have an effect. All of the examples above have pg.background(200) called right after instantiation and before anything else is drawn to them.

I’ll keep trying to replicate the problem in a MCVE, but would much appreciate any ideas on what’s going wrong.

1 Like

I think it’s because PGraphics make a bitmap image and when you rotate a bitamp image, processing makes some approximations.
if you want to rotate your figure properly you must do the rotation when drawing ( or re draw your figure) your figure not with PGraphics.

am I understandable enough (I’m not English fluent…)

1 Like

By default (w/o 3rd parameter) createGraphics() instantiates a JAVA2D PGraphics (PGraphicsJava2D):

Also, if you want your PGraphics to have all styles of the main canvas, you need to repeat each 1 you did to the main canvas to the off-screen PGraphics as well:

Here’s a Python Mode example about applying the same styles to both the main canvas and an off-screen canvas:

def setup():
    size(800, 600)

    applyStyles(g) # apply styles to the main canvas

    global pg
    pg = createGraphics(width, height)
    applyStyles(pg) # apply styles to an off-screen canvas

def applyStyles(pg, WEIGHT=1.5, STROKE=0xffFF00FF, FILL=-1):
    pg.primaryGraphics or pg.smooth(3)
    with pg.beginDraw():



    return pg

And its corresponding Java Mode too:

PGraphics pg;

void setup() {
  size(800, 600);

  applyStyles(getGraphics()); // apply styles to the main canvas

  pg = createGraphics(width, height);
  applyStyles(pg); // apply the same styles to an off-screen canvas

static final PGraphics applyStyles(final PGraphics pg) {




  return pg;
1 Like

Thanks. Are you suggesting the problem is that I’m not applying the correct setting to one of the PGraphics somewhere or is this just a by-the-way? Either way, useful I’ll try implementing -thanks.

Yea, just a guess that it might be the problem given we haven’t seen your code. :flushed:

Pay close attention to the renderer type and chosen smooth() level. :face_with_monocle:

1 Like

@GoToLoop You were right. Anything other than smooth(3) creates the jaggies for me. Thanks!