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

smooth()

Examples
void setup() {
  size(100, 100);
  smooth(2);
  noStroke();
}

void draw() {
  background(0);
  ellipse(30, 48, 36, 36);
  ellipse(70, 48, 36, 36);
}

int x = 0;

void setup() {
  fullScreen(P2D, SPAN);
  smooth(4);
}

void draw() {
  background(0);
  ellipse(x, height/2, height/4, height/4);
  x += 1;
}

PGraphics pg;
int x = 0;

void setup() {
  fullScreen(P2D);
  pg = createGraphics(width, height, P2D);
  pg.smooth(4);
}

void draw() {
  pg.beginDraw();
  pg.background(0);
  pg.ellipse(x, height/2, height/4, height/4);
  pg.endDraw();
  image(pg, 0, 0);
  x += 1;
}
Description Draws all geometry with smooth (anti-aliased) edges. This behavior is the default, so smooth() only needs to be used when a program needs to set the smoothing in a different way. The level parameter increases the amount of smoothness. This is the level of over sampling applied to the graphics buffer.

With the P2D and P3D renderers, smooth(2) is the default, this is called "2x anti-aliasing." The code smooth(4) is used for 4x anti-aliasing and smooth(8) is specified for "8x anti-aliasing." The maximum anti-aliasing level is determined by the hardware of the machine that is running the software, so smooth(4) and smooth(8) will not work with every computer.

The default renderer uses smooth(3) by default. This is bicubic smoothing. The other option for the default renderer is smooth(2), which is bilinear smoothing.

With Processing 3.0, smooth() is different than before. It was common to use smooth() and noSmooth() to turn on and off antialiasing within a sketch. Now, because of how the software has changed, smooth() can only be set once within a sketch. It can be used either at the top of a sketch without a setup(), or after the size() function when used in a sketch with setup(). The noSmooth() function also follows the same rules.

When smooth() is used with a PGraphics object, it should be run right after the object is created with createGraphics(), as shown in the Reference in the third example.
Syntax
smooth(level)
Parameters
level int: either 2, 3, 4, or 8 depending on the renderer
Returnsvoid
Updated on January 1, 2021 03:38:05am EST