# Circle Packing. Trying to implement on my project

**URL:** <https://discourse.processing.org/t/circle-packing-trying-to-implement-on-my-project/8368>\
**Category:** Coding Questions\
**Created:** [February 13, 2019, 5:59pm UTC](https://discourse.processing.org/t/circle-packing-trying-to-implement-on-my-project/8368 "2019-02-13T17:59:31Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [February 14, 2019, 1:23am UTC](https://discourse.processing.org/t/circle-packing-trying-to-implement-on-my-project/8368/5 "2019-02-14T01:23:54Z")

</div>

besides a math way to define/add new elements  
a other way  
is to generate random elements and add them ONLY after they  
passed a collision test with all other existing elements.

it turned out to be tricky as we needed to break loops on timeout.

we play something like this with rectangles here.

> [@Random position without overlapping](https://discourse.processing.org/t/random-position-without-overlapping/7904/12):
>
> sorry i can not help because your code can not be tested in my environment but current version also with random color: 
> 
> > **code:**
> >
> > //https://discourse.processing.org/t/random-position-without-overlapping/7904/8 //-1- make a class for a rectangle //-2- make a arraylist for many rectangles //-3- create "many" rectangles as array of this class // using random x y w h //-4- but after make that random set and before adding that rectangle to the list // check if…

the restriction by the outer shape must be added,  
also change rect with circle collision.

---

_[View the full topic](https://discourse.processing.org/t/circle-packing-trying-to-implement-on-my-project/8368)._
