[ Web Proxy ]
URL:
Viewing: https://processing.org/reference/dist_.html [Back]  [Original]

dist() / Reference / Processing.org
Skip to main content

Name

dist()

Description

Calculates the distance between twopoints.

Examples

  • Copy
    // Sets the background gray value based on the distance 
    // of the mouse from the center of the screen
    void draw() {
      noStroke();
      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);
      fill(gray);
      rect(0, 0, width, height);
    }
    

Syntax

  • dist(x1, y1, x2, y2)
  • dist(x1, y1, z1, x2, y2, z2)

Parameters

  • x1(float)x-coordinate of the firstpoint
  • y1(float)y-coordinate of the firstpoint
  • z1(float)z-coordinate of the firstpoint
  • x2(float)x-coordinate of the secondpoint
  • y2(float)y-coordinate of the secondpoint
  • z2(float)z-coordinate of the secondpoint

Return

  • float

Web Proxy Viewer  |  New URL  |  Original Page