The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 3 of 3

Thread: Filling the stage with various sized circles

  1. #1

    Filling the stage with various sized circles

    I'm in a bit of a mental block (perhaps it's getting too late once again, and too many nights without enough sleep thanks to my addiction to helping random strangers online with AS3.

    I was wanting to do a quick class that generates an image from another image similar to the way the Killers "Day and Age" album looked like:

    The problem I'm running into (mentally, haven't started coding yet) is that I'm not sure how to place all those randomly sized and placed circles on the stage in such a way that they will completely fill it.

    I have thought of two methods, but both seem inefficient:
    1. Use Box2D to create a new area where randomly sized circles drop from the top of the screen and fill the screen. Then, when all circles have settled, just track the size and position of each.
    2. Select a random spot on the screen. Create a new circle, and test how big it's maximum diameter can be until it bumps into other circles or reaches a set maximum diameter. If it cannot become larger than the smallest allowed diameter, don't place a circle there, but move on. Repeat until too many tries in a row don't allow you to place any more circles.

    Any other ideas?

    The goal is to FILL the screen with small circles of various sizes.
    Blog article of the month: Why My One Line 'if' Statements Are Unusual
    Twitter: @IQAndreas
    GitHub: IQAndreas

  2. #2
    It's against my policy to bump posts, but I'm still not able to get my head around how to accomplish this. Any ideas?

    I'm thinking option #2 might work, but it is likely to leave blank spots and holes in several places unless I really intensely loop through until I get perhaps 1000 in a row where no circles can fit in. Even then I can't guarantee anything.

    This is why I like it when objects are structured and arranged neatly and symmetrically (like a grid) on the stage. I have tried 3D modeling, but somehow I couldn't really get my models looking right, most likely because I completely refuse to turn off "snap to grid". I do make some really nice robots and perfectly shaped buildings.
    Blog article of the month: Why My One Line 'if' Statements Are Unusual
    Twitter: @IQAndreas
    GitHub: IQAndreas

  3. #3
    I've done exactly what you describe.

    I simply added a circle one at a time and made it grow whilst checking distance with every other circle in the array. If the distance was more than the combined size of it's radius plus the radius of whatever circle it was being checked with, it would stop growing, and generate another circle.

    There were no more blank spots than the image you posted, but there were much bigger circles.

    You could stop that by simply putting

    if (distance < new_circle.radius+curr_circle.radius || new_circle.width > 200) {

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012