We are about to switch to a new forum software. Until then we have removed the registration on this forum.
PGraphics p;
void setup() {
size(600, 600);
p = createGraphics(600, 600);
p.beginDraw();
p.rectMode(CENTER);
translate(width/2, height/2);
p.rect(0, 0, 50, 50);
p.endDraw();
image(p, 0, 0);
}
I have just begun and I'm already stuck :/
Answers
If you remove the translate call, would it be cut off?
Kf
That's what has been creating it, yes. I'm just wondering why is it not rendering anything in any other quadrant, past the origin.
Instead of translate maybe p.translate...?
Oh thanks, I didn't know that was an option. For some reason, I thought translating functions such as translate, rotate and push and pop affect all PGraphics, along with the main sketch, ergo that they don't require the dot syntax at the beginning.
p. is required before translate otherwise it applies only to line 10
Solved now...?
translate()
moves the canvas origin to 300, 300. It is reset when draw exits. Nowimage(p, -300, -300)
aligns the image to the top corner of the canvas.p.translate(300, 300)
moves the drawing origin of the PGraphics or PImage. No matter where you choose to draw it withimage()
, all its content is offset by that amount. Nowp.rect(-300,-300, 600, 600)
aligns a rect to the top corner of the image.So, you are either moving the piece of paper on the table, or moving where you start drawing on that piece of paper.