Draw to off-screen buf. -> render it to image -> move image with everything drawn on it. Doesn't work
in
Programming Questions
•
7 months ago
I made a simple audio visualisation sketch but cannot achieve an effect of a fading trace.
Here's a working snippet (without audio stuff, just drawing)
1) draw a circle into off-screen, shifting x coordinate on every iteration.
2) making an image from buffer - image(pg,0,0);
3) shift that image -x, so that the freshly drawn circle appears in the same place and trace goes left.
But somehow it doesn't work. When i'm trying to shift an image, circle is being drawn in the same place without a trace.
Seems like there's something i don't understand about PGraphics.
Any ideas?
Here's a working snippet (without audio stuff, just drawing)
- PGraphics pg;
int x = 0,side = 400;
void setup() {
size(side, side,P2D);
pg = createGraphics(side, side, P2D);
}
void draw() {
pg.beginDraw();
pg.background(0,5);
pg.stroke(255);
float coord = sin(radians(x))*side/2;
pg.ellipse(width/2,height/2, coord, coord);
pg.endDraw();
image(pg, 0, 0);
x++;
if(x>=360) x = 0;
}
1) draw a circle into off-screen, shifting x coordinate on every iteration.
2) making an image from buffer - image(pg,0,0);
3) shift that image -x, so that the freshly drawn circle appears in the same place and trace goes left.
But somehow it doesn't work. When i'm trying to shift an image, circle is being drawn in the same place without a trace.
Seems like there's something i don't understand about PGraphics.
Any ideas?
1