#Non-overlapping text in p5.js

1 messages · Page 1 of 1 (latest)

heavy dune
#

Hello! I am having an issue with a program I'm writing in p5.js. The goal is to create a wall of text that gradually disappears unless you click on specific words to keep them there. So far, I have managed to do that, but I haven't found a way to keep the text from overlapping each other. I watched the video on non-overlapping circles but since rectangles don't have a radius but a height and width, using the distance function doesn't work. Furthermore, I would like for all words in the word file to be displayed, so I can't just not display it if it overlaps and draw another one.
I'm hoping someone here could point me in the right direction regarding this, or maybe someone has ideas on what I could try.

here is the code I have so far (the text is in a separate file from the sketch)
Thanks in advance for any help 🙂

round knoll
heady igloo
heavy dune
#

I tried to make a function to check overlap and it seems to work, but now I have the problem that the while loop doesn't work for some reason. What am I missing? (r45)

round knoll
#

I think your problem is you only check if you are overlapping box k, if you overlap you resample position. but after resampling you only check if you are overlapping box k, but not all boxes before that. So after resampling you might be overlapping some other box. Create a function checkAllBoxes(currentBox, allBoxes) which always checks all boxes and return true if there is any overlap, false if not

#

like this (i did no test this)

function checkAllBoxes(currentBox, allBoxes) {
  for(let box of allBoxes) {
    if(box == currentBox) continue
    if(overlapping(box, currentBox)) return true
  }

  return false 
}
#

get rid of for(k) loop and just put while(checkAllBoxes(box, boxes))... instead