Hi there, I am currently working on an animation that for example if you create 4 balls, then ball1 going to link ball2, ball3, ball4 and ball2 going to link ball3 and ball4, keep going…
The problem is that every time I want to add a new ball, then I have to add a bunch of arrays for containing points, directions… I know I need to add several loops there but still not figure out where to put those loops, here is my code currently, please help!

This sketch has a class that draws a line from every ball to every ball. I didn’t have time to dig into the animation you’re doing but, if I understand what you’re trying to do, your question is “where to put those loops” and the code linked above is moving toward the answer: "all the loops become methods of the class.

Note: that code is pretty sloppy and outside good OO (the class is referencing the global Ball array] but I didn’t want to complicate the approach I’m suggesting, which is that you put your loops in one class and then call them. Note that this is also creating overlapping lines since every ball is drawing to every ball.

Hi Adam,
Thank you for your answers. Since the balls’ positions are static however the lines will keep growing, I separate the balls and lines into two different classes and as you said set the loops as methods of the lines class. Now it is working and that helps me better understand working with objects. Thank you so much for your help.