A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Calculating largest "open" rectangular area?

  1. #1
    Junior Member
    Join Date
    May 2000
    Posts
    26
    I have a directory of photographs (compiled as .swf's) that I'm dynamically loading and displaying on a 600x800 screen. When created, each fades itself in, then back out, then creates a new instance and starts the process for the next photo before self-destructing. About 5 to 8 are on screen at any given time.

    I want these to continue to position themselves at random points on the screen so that each time the movie is played, different photos are loaded and also positioned differently. The problem is that as they are positioned randomly, they sometimes overlap.

    If I register the x/y coordinates for each rectangle as it's created, as well as it's width/height, there should be some means of determining where the largest "empty" are on the screen is and then centering the next photo in the middle of this area. Without a strong math or CS background, I'm having trouble doing this.

    Would anyone mind telling me how you'd approach this in Flash 5?

    Thanks,

    Gary
    g.dejarnett@ttu.edu

  2. #2
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    Interesting problem.

    Before the photo fades in, have a few frames where it's completely invisible. Before it appears, check to see if it's colliding with another photo. If it is, then take it out and replace randomly again until it doesn't overlap.

    In effect, rather than working out where it should go, you're moving it around until it isnt hitting anything else.

    It doesn't answer the question of how to calculate the largest empty area, but it does answer the question of how I'd approach the problem.

  3. #3
    Junior Member
    Join Date
    May 2000
    Posts
    26
    Thanks for the suggestion, Lesli.

    Yes, that's exactly the approach (collision detection) I was planning to take if no one had a formula for the largest open space. I'll see how it looks.

    The only thing I was concerned about is that it would be very easy for pictures to be barely not overlapping, and thus be all crowded over in the corner with a vast open area remaining on the page. In that case people would wonder why I was too lazy to distribute them better, and I'd lose the effect I'm shooting for (recalling old memories).

    Thanks again,

    Gary

  4. #4
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    You could of course divide the screen up into sections (for argument's sake, lets say four quadrants) And have the picture's appear in a random position within a random quadrant. That would give a random appearance and also force the pictures to space out around the screen.

    Another possible solution to having pictures occupying one corner of the screen would be to have them start in the centre and filter outwards in random directions until they hit a 'clean' spot.

    In fact, don't use a random direction, increment using an angle that won't repeat too often, like 150 degrees.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center