Name

clear()

Description

Clears the pixels within a buffer. This function only works on PGraphics objects created with the createGraphics() function. Unlike the main graphics context (the display window), pixels in additional graphics areas created with createGraphics() can be entirely or partially transparent. This function clears everything in a PGraphics object to make all the pixels 100% transparent.

Examples

  • PGraphics pg;
    
    void setup() {
      size(200, 200);
      pg = createGraphics(width, height);
    }
    
    void draw() {
      background(204);
      
      // Clear the PGraphics when the mouse is pressed
      if (mousePressed == true) {
        pg.beginDraw(); 
        pg.clear();
        pg.endDraw();
      } else {
        pg.beginDraw();
        pg.stroke(0, 102, 153);
        pg.line(width/2, height/2, mouseX, mouseY);
        pg.endDraw();
      }
    
      image(pg, 0, 0);
    }
    

Syntax

  • clear()

Return

  • void