# Is there an algorithm or coding example that may help me here?

**URL:** <https://discourse.processing.org/t/is-there-an-algorithm-or-coding-example-that-may-help-me-here/39103>\
**Category:** Coding Questions\
**Created:** [October 5, 2022, 6:57pm UTC](https://discourse.processing.org/t/is-there-an-algorithm-or-coding-example-that-may-help-me-here/39103 "2022-10-05T18:57:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![blackhatProphet](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@blackhatProphet](https://discourse.processing.org/u/blackhatProphet)\
**Post date:** [October 5, 2022, 6:57pm UTC](https://discourse.processing.org/t/is-there-an-algorithm-or-coding-example-that-may-help-me-here/39103/1 "2022-10-05T18:57:34Z")

</div>

Hi I am working on a personal project and I was hoping to get some help trying to wrap my head around how best to go about this part of the project.

So what I am envisioning:

1. The program is given a string array **(completed)**

2. The program will then take the string array and in random parts of the display area create a text object that displays the current string at stringArray[i] **(completed)**  
3.The text objects should be varying sizes (3-4 text sizes) **(completed)**

3. The text objects varying directions (vertical or horizontal)

4. The text objects should not overlap one another  
_(finally, and this one may be the most complex, so might not be the one I do, unless I’m just overthinking this part)_

5. The content of the string array should all be able to fit into and fill the entirety of the display area (size of the display area remains constant)

For a visual explanation of what I’m going for:  
 ![wordCloud](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/e/3/e30429090a3e24aa3aeb3b5fa540a9b1f62a5a1e.png)

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [October 5, 2022, 7:23pm UTC](https://discourse.processing.org/t/is-there-an-algorithm-or-coding-example-that-may-help-me-here/39103/2 "2022-10-05T19:23:53Z")

</div>

> [@blackhatProphet](#):
>
> The text objects should not overlap one another  
> _(finally, and this one may be the most complex, so might not be the one I do, unless I’m just overthinking this part)_

Hi  
collision-detection may work

> **[Collision Detection](http://jeffreythompson.org/collision-detection/circle-rect.php)**
>
> An online book about collision detection using Processing.

> **[Processing Collision Detection](https://happycoding.io/tutorials/processing/collision-detection)**
>
> Learn how to trigger an action when objects overlap in Processing!

---

<div class="post-metadata">

**Author:** ![vkbr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/vkbr/32/16844_2.png) [@vkbr](https://discourse.processing.org/u/vkbr)\
**Post date:** [October 5, 2022, 7:34pm UTC](https://discourse.processing.org/t/is-there-an-algorithm-or-coding-example-that-may-help-me-here/39103/3 "2022-10-05T19:34:54Z")

</div>

I think what you need to google is packing algorithm, more easy to find rectangle packing or circle packing. Also there is fresh a topic here about circle packing going on…

[https://discourse.processing.org/t/how-to-generate-points-ellipse-within-a-circle-area/20933/15](https://discourse.processing.org/t/how-to-generate-points-ellipse-within-a-circle-area/20933/15)

The idea anyway is to:  
.store all stuff drew (rect shapes whatever)  
.create next one  
.compare all of them to see if they overlap(here comes the collision detection)  
.if it serves draw and store  
.else try smaller or in different directions, fonts, whatever…  
.Collision detection of the bounding box of text is not hard.  
.For ‘uneven blobs’ its not trivial.  
.There are some libraries that might help.  
.It can also be done by testing for colors in a not displayed pGraphics instead of geometrically.

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [October 5, 2022, 7:52pm UTC](https://discourse.processing.org/t/is-there-an-algorithm-or-coding-example-that-may-help-me-here/39103/4 "2022-10-05T19:52:58Z")

</div>

Some hints

[![](https://img.youtube.com/vi/NLzne4XaR3M/hqdefault.jpg "13.1 Strings and Drawing Text - Processing Tutorial") ](https://www.youtube.com/watch?v=NLzne4XaR3M&t=7s)

---

<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:** [October 5, 2022, 10:38pm UTC](https://discourse.processing.org/t/is-there-an-algorithm-or-coding-example-that-may-help-me-here/39103/5 "2022-10-05T22:38:30Z")

</div>

> <https://stackoverflow.com/questions/342687/algorithm-to-implement-a-word-cloud-like-wordle>
