Karrajo
October 19, 2021, 12:26am
1
Hi, I’m trying to convert some code to PGraphics because I want to save the result in a bigger size, but I’m using a “for” part, and I can’t find the right way to make that everything works like in the code without PGraphics.
I don’t find help in other topics of the forum, neither in the reference page.
My original code is:
float t=1;
void setup() {
size(900, 900);
}
void draw() {
background(#FFFFFF);
fill(#000000);
translate(width/4, height/4);
for (int i = 0; i < 50; i++) {
float x1 = i;
float y2 = t*i*4;
ellipse(x1, y2, 10, 10);
}
t += 0.01;
And I thought this would work, but it isn’t:
PGraphics pg;
float t=1;
void setup() {
size(900, 900);
pg=createGraphics(width, height);
}
void draw() {
pg.beginDraw();
pg.background(#FFFFFF);
pg.fill(#000000);
pg.translate(width/4, height/4);
for (int i = 0; i < 50; i++) {
float x1 = i;
float y2 = t*i*4;
pg.ellipse(x1, y2, 10, 10);
pg.endDraw();
image(pg, 0, 0);
}
t += 0.01;
Anyone can help me?
glv
October 19, 2021, 12:53am
2
Hello,
void draw()
{
pg.beginDraw();
pg.background(#FFFFFF);
pg.fill(#000000);
pg.translate(width/4, height/4);
for (int i = 0; i < 50; i++)
{
float x1 = i;
float y2 = t*i*4;
pg.ellipse(x1, y2, 10, 10);
}
pg.endDraw();
image(pg, 0, 0);
t += 0.01;
}
:)
jafal
October 19, 2021, 1:00am
3
Hi
You have same error in both codes
float t=1;
void setup() {
size(900, 900);
}
void draw() {
background(#FFFFFF);
fill(#000000);
translate(width/4, height/4);
for (int i = 0; i < 50; i++) {
float x1 = i;
float y2 = t*i*4;
ellipse(x1, y2, 10, 10);
t += 0.01;
}
}
// t += 0.01;
jafal
October 19, 2021, 1:01am
4
PGraphics pg;
float t=1;
void setup() {
size(900, 900);
pg=createGraphics(width, height);
}
void draw() {
pg.beginDraw();
pg.background(#FFFFFF);
pg.fill(#000000);
pg.translate(width/4, height/4);
for (int i = 0; i < 50; i++) {
float x1 = i;
float y2 = t*i*4;
pg.ellipse(x1, y2, 11, 10);
pg.endDraw();
image(pg, 0, 0);
t += 0.01;
}
}
// t += 0.01;
Thank you very much, glv, it was so easy! (but not for me)
1 Like
jafal, thank you but it doesn’t work like I expected, with the code of glv it’s perfect for me, so I’m not sure if that was an error or a different way to do it
2 Likes
jafal
October 19, 2021, 1:29am
7
@Karrajo yes glv way is correct
pg.ellipse(x1, y2, 10, 10);
}
pg.endDraw();
image(pg, 0, 0);
t += 0.01;
}