This reference is for Processing 3.0+. If you have a previous version, use the reference included with your software in the Help menu. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries Javadoc.

Name

clear()

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);
}
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 of the pixels 100% transparent.
Syntax
clear()
Returnsvoid
Updated on January 1, 2021 03:38:08am EST