Learn creative coding writing simple programs

65. Are we getting close? Use dist() to find out the distance

The dist() function can be used to find out the distance between to points. In our example we test how far is a moving circle from the mouse pointer by writing: float d = dist(x, y, mouseX, mouseY);
Now that we know the distance, we can do different things when we are getting close to our destination.

Tags: dist, distance, Lesson

Code editor

You can make changes to the code below. Then

Questions and comments

Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)

To indicate that a word in your comment is code, use the `backtick`. Example
  Do `float` and `int` smell similar?
To highlight code blocks, use ```processing and ``` like this:
  void setup() {
    size(600, 600);