All Questions



about the rect2's inside order

I have a hard time understanding the logic construction behind these:

            room.grow_individual(-unit.x, 0, -unit.x, unit.y - room.size.y),
            room.grow_individual(unit.x - room.size.x, -unit.y, 0, -unit.y),
            room.grow_individual(-unit.x, unit.y - room.size.y, -unit.x, 0),
            room.grow_individual(0, -unit.y, unit.x - room.size.x, -unit.y)

why are we increasing the sizes this way?

I understood the it's related to picking to sort the array either by x or y but what is the logic behind it?

  • Nathan Lovato replied

    This isn't increasing the sizes. It's creating four rectangles aligned with the top, right, bottom, and left edges of the total room rectangle. That the code uses Rect2.grow_individual to do so is an implementation detail. See the image in the tutorial again, the 3rd image shows the result this step produces with the four rectangles named a, b, c, and d.

    Please let me know if you need a more detailed explanation. It's a little hard to put in words.

  • A
    SnowRoad11 replied

    I think I got you.

    It just didn't sink in enough so I can play with these numbers in the same logic and maintain the code usability.

  • Nathan Lovato replied

    Using that Rect2.grow_individual() isn't as explicit as creating a new rectangle from scratch, but the trick is noticing how we shrink rectangles by using negative values in the function call

    unit.x - room.size.x

    Here, room.size.x may be ten times bigger than unit.x, so the expression shrinks the rectangle quite a lot, producing the thin rectangle shown in the lesson.

    The general algorithm is:

    1. We calculate a border inside the rectangle
    2. We find random points inside that border
    3. We connect the points

    Resulting in that organic shape.

  • A
    SnowRoad11 replied

    thank you so much. it finally sinked in.

    we are creating these small "strips"/border area of rectangles like in the the image with 3 on it and then picking a position from them based on their orientation.

    0 = top border

    1 = right border

    2 = bottom border

    3 = left border

    did I get it right?