public void backgroundImpl() { if (backgroundAlpha) { // Create a small array that can be used to set the pixels several times. // Using a single-pixel line of length 'width' is a tradeoff between // speed (setting each pixel individually is too slow) and memory // (an array for width*height would waste lots of memory if it stayed // resident, and would terrify the gc if it were re-created on each trip // to background(). WritableRaster raster = ((BufferedImage) image).getRaster(); if ((clearPixels == null) || (clearPixels.length < width)) { clearPixels = new int[width]; } java.util.Arrays.fill(clearPixels, backgroundColor); for (int i = 0; i < height; i++) { raster.setDataElements(0, i, width, 1, clearPixels); } } else { // new Exception().printStackTrace(System.out); // in case people do transformations before background(), // need to handle this with a push/reset/pop pushMatrix(); resetMatrix(); g2.setColor(new Color(backgroundColor)); // , backgroundAlpha)); g2.fillRect(0, 0, width, height); popMatrix(); } }