Line between balls

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:

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() {

  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) {
        line(location.x, location.y, other.location.x, other.location.y);


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

1 Like

Here in the last video maybe?

This is not a right video unfortunately

1 Like

@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 for example.


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

I started here:

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

Give it a try!

’ :slight_smile: ’



oh thankyou very much

1 Like