Function clear() does not exist
in
Programming Questions
•
8 months ago
HI,
I'm attempting to create an animation in Processing (v 2.0b7 on a Mac) using a PGraphics object and saving the frames to png files. The motion works perfectly and the files save fine, but I need to clear the graphic between each frame and since I am using transparency, I can't simply set a new background. From the online documentation, including the Javadoc for the PGraphics class, it would appear that calling the clear() method should do exactly what I want. However, when I include this call I get a compile error with the message in the title of this post.
Any ideas what I'm doing wrong, or if there's a better way of doing this? I'll paste in a portion of my code below to show what I'm doing ...
Many thanks
Nick
- PGraphics pg;
- float originX, origin Y, a, b;
- void setup() {
- size(600, 600, P3D);
- pg = createGraphics(600, 600, P3D);
- smooth();
- frameRate(16);
- // code to set up position, rotation etc ...
- }
- void pgDrawLoop(float originX, float originY, float rotationX, float rotationY) {
- pg.beginDraw();
- pg.pushMatrix();
- pg.translate(originX, originY);
- pg.pushMatrix();
- pg.stroke(217, 67, 100);
- pg.strokeWeight(3);
- pg.noFill();
- pg.rotateX(rotationX);
- pg.rotateY(rotationY);
- pg.translate(0, 0);
- pg.beginShape();
- pg.vertex(0, -200, 0);
- pg.bezierVertex(160, -200, 200, -160, 200, 0);
- pg.bezierVertex(200, 160, 160, 200, 0, 200);
- pg.bezierVertex(-160, 200, -200, 160, -200, 0);
- pg.bezierVertex(-200, -160, -160, -200, 0, -200);
- pg.endShape();
- pg.popMatrix();
- pg.rotateX(-rotationX);
- pg.rotateY(-rotationY);
- pg.popMatrix();
- pg.endDraw();
- }
- void draw() {
- if(frameCount > 400) {
- exit();
- }
- // Code to calculate position and rotation here ...
- pg.clear();
- pg.background(0,0,0,0);
- pgDrawLoop(originX1, originY1, a, b);
- image(pg, 0, 0);
- }
1