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.



// Sets the background gray value based on the distance 
// of the mouse from the center of the screen
void draw() {
  float d = dist(width/2, height/2, mouseX, mouseY);
  float maxDist = dist(0, 0, width/2, height/2);
  float gray = map(d, 0, maxDist, 0, 255);
  rect(0, 0, width, height);
Description Calculates the distance between two points.
dist(x1, y1, x2, y2)
dist(x1, y1, z1, x2, y2, z2)
x1 float: x-coordinate of the first point
y1 float: y-coordinate of the first point
z1 float: z-coordinate of the first point
x2 float: x-coordinate of the second point
y2 float: y-coordinate of the second point
z2 float: z-coordinate of the second point
Updated on January 1, 2021 03:38:06am EST