# Line between balls

**URL:** <https://discourse.processing.org/t/line-between-balls/17606>\
**Category:** Coding Questions\
**Created:** [February 7, 2020, 9:02am UTC](https://discourse.processing.org/t/line-between-balls/17606 "2020-02-07T09:02:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![l3ehfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/l3ehfar/32/4074_2.png) [@l3ehfar](https://discourse.processing.org/u/l3ehfar)\
**Post date:** [February 7, 2020, 9:02am UTC](https://discourse.processing.org/t/line-between-balls/17606/1 "2020-02-07T09:02:15Z")

</div>

Hi I remember I watched a tutorial of coding train channel a year ago that implement a line between balls in a particular distance as above:

```auto
class Ball {

  PVector org, location;
  float a = 10;
  float theta, radius, offSet;
  int s, dir, d = 50;

  Ball(PVector _org, PVector _location, float _radius, int _dir, float _offSet) {
    org = _org;
    location = _location;
    radius = _radius;
    dir = _dir;
    offSet = _offSet;
  }

  void run() {
 
    move();
    lineBetween();
  }

  void move() {
    location.x = org.x + sin(theta+offSet)*radius;
    location.y = org.y + cos(theta+offSet)*radius;
    theta += (0.04/4*dir);
  }

  void lineBetween() {
    for (int i=0; i<ballCollection.size(); i++) {
      Ball other = (Ball) ballCollection.get(i);
      float distance = location.dist(other.location);
      if (distance >0 && distance < d) {
        stroke(250,250,200);
        line(location.x, location.y, other.location.x, other.location.y);
      }
    }
  }

 
}

```

can anyone help me find aforementioned tutorial or the source code in p5js?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 7, 2020, 10:22am UTC](https://discourse.processing.org/t/line-between-balls/17606/2 "2020-02-07T10:22:31Z")

</div>

Here in the last video maybe?

https://www.youtube.com/embed/videoseries?list=PLRqwX-V7Uu6ZwSmtE13iJBcoI-r4y7iEc&wmode=transparent&rel=0&autohide=1&showinfo=1&enablejsapi=1

---

<div class="post-metadata">

**Author:** ![l3ehfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/l3ehfar/32/4074_2.png) [@l3ehfar](https://discourse.processing.org/u/l3ehfar)\
**Post date:** [February 9, 2020, 11:27am UTC](https://discourse.processing.org/t/line-between-balls/17606/3 "2020-02-09T11:27:17Z")

</div>

This is not a right video unfortunately

---

<div class="post-metadata">

**Author:** ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)\
**Post date:** [February 9, 2020, 5:21pm UTC](https://discourse.processing.org/t/line-between-balls/17606/4 "2020-02-09T17:21:20Z")

</div>

@l3ehfar I can’t find the video but searching the `lineBetween()` function in Github might yield interesting results.

I found very similar Processing sketches dating back to 2015 but most are from June 2018. See [this one](https://github.com/jbobrow/OpenProcessingExperiments/blob/35f9f277f01ec4200fff25685c89fafda59ebdc0/sketches/processing_147108/processing_147108.pde) for example.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [February 11, 2020, 10:59pm UTC](https://discourse.processing.org/t/line-between-balls/17606/5 "2020-02-11T22:59:13Z")

</div>

> [@l3ehfar](#):
>
> can anyone help me find aforementioned tutorial or the source code in p5js?

I was able to port this to P5.js and I have little experience with P5.js.

I started here:

> **[examples | p5.js](https://p5js.org/examples/objects-objects.html)**
>
> p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.

> **[examples | p5.js](https://p5js.org/examples/arrays-array-objects.html)**
>
> p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.

> **[reference | p5.js](https://p5js.org/reference/#/p5/append)**
>
> p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.

And selectively went through the Coding Train videos for p5.js:

> **[The Coding Train](https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1_aw)**
>
> All aboard! The Coding Train is on its way with creative coding video tutorials on subjects ranging from the basics of programming languages like JavaScript to algorithmic art, machine learning, simulation, generative poetry, and more. Choo choo!

Give it a try!

’ 🙂 ’

Output:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/9f52d4e6cdaadf943993b4a5dc0a9aedd72a7067.png)

---

<div class="post-metadata">

**Author:** ![l3ehfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/l3ehfar/32/4074_2.png) [@l3ehfar](https://discourse.processing.org/u/l3ehfar)\
**Post date:** [February 13, 2020, 2:38pm UTC](https://discourse.processing.org/t/line-between-balls/17606/6 "2020-02-13T14:38:31Z")

</div>

oh thankyou very much
