Can someone please help me to get rotate to work with pgraphics in the following code. This code calls a function that draws a ‘petal’ that I would like to rotate and which was working perfectly without PGraphics.
<
p.beginDraw();
p.noFill();
rt1 = rx(); // random control points
rt2 = ry();
int num = int(random(5, 21));
int angle = int(random(-360, 360));
int dir = int(random(1, 3));
if (dir == 1) dir = -360;
if (dir == 2) dir = 360;
for (int j = 0; j<num; j++) {
p.pushMatrix();
p.rotate(radians(dir) / num * j);
drawPetal(p, x, y, r, rt1, rt2 );
Code looks solid, I don’t see any problem there. I had a problem with transformations and PGraphics. I applied transformation each time I draw stuff to PGraphics. But it behaves differently than draw() cycle. It doesn’t reset transformations at start of each draw cycle(), it just kept piling them up and my drawings were after couple of loops outside of drawing area.
I guess you have bumped in to same problem. For me solution was simple. I used identical transformation each time so I moved it to setup(). For varying transformations you need to reset the stack of transformations in code.