# How can I make a new ball from colliding?

**URL:** <https://discourse.processing.org/t/how-can-i-make-a-new-ball-from-colliding/23055>\
**Category:** Processing\
**Tags:** homework\
**Created:** [August 5, 2020, 9:16am UTC](https://discourse.processing.org/t/how-can-i-make-a-new-ball-from-colliding/23055 "2020-08-05T09:16:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![terry0728](https://avatars.discourse-cdn.com/v4/letter/t/ce7236/32.png) [@terry0728](https://discourse.processing.org/u/terry0728)\
**Post date:** [August 5, 2020, 9:16am UTC](https://discourse.processing.org/t/how-can-i-make-a-new-ball-from-colliding/23055/1 "2020-08-05T09:16:48Z")

</div>

In the example of “bouncy bubbles” that collide with each other, I would like to program a new ball to be created at that point when two balls collide. What should I do?

bouncing bubbles -\> [https://processing.org/examples/bouncybubbles.html](https://processing.org/examples/bouncybubbles.html)

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [August 5, 2020, 10:36am UTC](https://discourse.processing.org/t/how-can-i-make-a-new-ball-from-colliding/23055/2 "2020-08-05T10:36:46Z")

</div>

You need to use some math. Collisions between 2 points of the same size happen at the distance between two points/2 therefore if you know where a point is you can simply add that last calculation to one of the points, then you just call create new point and add it to the points array.

If they aren’t the same size than it will be (radius of point 1 + radius of point 2)/2

---

<div class="post-metadata">

**Author:** ![terry0728](https://avatars.discourse-cdn.com/v4/letter/t/ce7236/32.png) [@terry0728](https://discourse.processing.org/u/terry0728)\
**Post date:** [August 5, 2020, 11:18am UTC](https://discourse.processing.org/t/how-can-i-make-a-new-ball-from-colliding/23055/3 "2020-08-05T11:18:58Z")

</div>

I know that, but I don’t know where to add the code ‘balls.add();’ Should I put it in the collide function in the ball class? I really don’t know what to do.

2020년 8월 5일 (수) 오후 7:46, paul goux via Processing Foundation \<[processingfoundation1@discoursemail.com](mailto:processingfoundation1@discoursemail.com)\>님이 작성:

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [August 5, 2020, 11:43am UTC](https://discourse.processing.org/t/how-can-i-make-a-new-ball-from-colliding/23055/4 "2020-08-05T11:43:24Z")

</div>

Doesn’t necessarily matter where you add it so long as it allows proper timing, ie should be done before the end of draw, and you should probably not do it after all collisions have been checked because your new points might have caused collisions which now won’t be checked until they are initialised and therefore they will be running one frame behind.

Don’t have the code to hand ATM but if you can locate the collide code I would probably put it there.

---

<div class="post-metadata">

**Author:** ![terry0728](https://avatars.discourse-cdn.com/v4/letter/t/ce7236/32.png) [@terry0728](https://discourse.processing.org/u/terry0728)\
**Post date:** [August 5, 2020, 12:08pm UTC](https://discourse.processing.org/t/how-can-i-make-a-new-ball-from-colliding/23055/5 "2020-08-05T12:08:44Z")

</div>

How can I write the code when I want to add more class in the class function code?

2020년 8월 5일 (수) 오후 8:53, paul goux via Processing Foundation \<[processingfoundation1@discoursemail.com](mailto:processingfoundation1@discoursemail.com)\>님이 작성:

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [August 5, 2020, 1:44pm UTC](https://discourse.processing.org/t/how-can-i-make-a-new-ball-from-colliding/23055/6 "2020-08-05T13:44:41Z")

</div>

Don’t have the example to hand ATM but there should be a points array in the sketch which keeps track of the points, after checking collisions using the function from the class just add the relevant point
