dist()

Calculates the distance between two points.

Examples

1
2
3
4
5
6
7
8
9
# Sets the background gray value based on the distance
# of the mouse from the center of the screen
def draw():
  py5.no_stroke()
  d = py5.dist(py5.width/2, py5.height/2, py5.mouse_x, py5.mouse_y)
  max_dist = py5.dist(0, 0, py5.width/2, py5.height/2)
  gray = py5.remap(d, 0, max_dist, 0, 255)
  py5.fill(gray)
  py5.rect(0, 0, py5.width, py5.height)

Description

Calculates the distance between two points.

Syntax

dist(x1: float, y1: float, x2: float, y2: float) -> float
dist(x1: float, y1: float, z1: float, x2: float, y2: float, z2: float) -> float

Parameters

  • x1: float - x-coordinate of the first point

  • x2: float - x-coordinate of the second point

  • y1: float - y-coordinate of the first point

  • y2: float - y-coordinate of the second point

  • z1: float - z-coordinate of the first point

  • z2: float - z-coordinate of the second point

Updated on September 11, 2021 16:51:34pm UTC