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(100, 100);
}

void draw() {
  background(204);
  pg.beginDraw();
  pg.stroke(0, 102, 153);
  pg.line(0, 0, mouseX, mouseY);
  pg.endDraw();
  image(pg, 50, 50); 
}

// Click to clear the PGraphics object
void mousePressed() {
  pg.beginDraw(); 
  pg.clear();
  pg.endDraw(); 
}
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 March 16, 2016 10:39:09am EDT

Creative Commons License