createGraphics in a loop
in
Programming Questions
•
1 year ago
hi,
i am drawing to a buffer for a project, but realized that the screen wouldn't redraw. i moved my background(0); from draw() to within beginDraw() and endDraw(). however, it doesn't work. i could do without the buffer, but i am curious as to why this is an issue. here is some sample code that replicates the problem:
PGraphics pg;
int increment = 10;
void setup() {
size(600, 600);
pg = createGraphics(600, 600, P2D);
}
void draw() {
// background(0);
drawEllipse();
}
void drawEllipse()
{
for(int x = 0; x < width; x += 10)
{
for(int y = 0; y < height; y += 10)
{
pg.beginDraw();
pg.background(0);
pg.smooth();
pg.noFill();
pg.stroke(255);
pg.ellipse(increment/2 + (x * increment), increment/2 + (y * increment), 20, 20);
pg.endDraw();
}
}
image(pg, 0, 0);
}
thanks,
destro.
i am drawing to a buffer for a project, but realized that the screen wouldn't redraw. i moved my background(0); from draw() to within beginDraw() and endDraw(). however, it doesn't work. i could do without the buffer, but i am curious as to why this is an issue. here is some sample code that replicates the problem:
PGraphics pg;
int increment = 10;
void setup() {
size(600, 600);
pg = createGraphics(600, 600, P2D);
}
void draw() {
// background(0);
drawEllipse();
}
void drawEllipse()
{
for(int x = 0; x < width; x += 10)
{
for(int y = 0; y < height; y += 10)
{
pg.beginDraw();
pg.background(0);
pg.smooth();
pg.noFill();
pg.stroke(255);
pg.ellipse(increment/2 + (x * increment), increment/2 + (y * increment), 20, 20);
pg.endDraw();
}
}
image(pg, 0, 0);
}
thanks,
destro.
1