How to use the flax.geometry.Blob.from_rectangle function in flax

To help you get started, we’ve selected a few flax examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eevee / flax / flax / fractor.py View on Github external
random_normal_range(9, int(self.region.height * 0.4)),
        )

        room_position = self.region.center() - room_size // 2
        room_position += Point(
            random_normal_int(0, self.region.width * 0.1),
            random_normal_int(0, self.region.height * 0.1),
        )

        room_rect = Rectangle(room_position, room_size)
        self.room_region = room_rect

        room = Room(room_rect)

        cave_area = (
            Blob.from_rectangle(self.region)
            - Blob.from_rectangle(room_rect)
        )
        self.cave_region = cave_area
        walls = [point for (point, _) in self.region.iter_border()]
        floors = []
        for point, edge in room_rect.iter_border():
            if edge is side or edge.adjacent_to(side):
                floors.append(point)
                floors.append(point + side)
        generate_caves(
            self.map_canvas, cave_area, CaveWall,
            force_walls=walls, force_floors=floors,
        )

        room.draw_to_canvas(self.map_canvas)
github eevee / flax / flax / fractor.py View on Github external
)

        room_position = self.region.center() - room_size // 2
        room_position += Point(
            random_normal_int(0, self.region.width * 0.1),
            random_normal_int(0, self.region.height * 0.1),
        )

        room_rect = Rectangle(room_position, room_size)
        self.room_region = room_rect

        room = Room(room_rect)

        cave_area = (
            Blob.from_rectangle(self.region)
            - Blob.from_rectangle(room_rect)
        )
        self.cave_region = cave_area
        walls = [point for (point, _) in self.region.iter_border()]
        floors = []
        for point, edge in room_rect.iter_border():
            if edge is side or edge.adjacent_to(side):
                floors.append(point)
                floors.append(point + side)
        generate_caves(
            self.map_canvas, cave_area, CaveWall,
            force_walls=walls, force_floors=floors,
        )

        room.draw_to_canvas(self.map_canvas)

        # OK, now draw a gate in the middle of the side wall
github eevee / flax / flax / fractor.py View on Github external
# Add some doors for funsies.
        locked_room = random.choice(rooms)
        for rect in rooms:
            x = random.randrange(rect.left + 1, rect.right - 1)
            if rect.top > hallway.top:
                side = Direction.down
            else:
                side = Direction.up
            point = rect.edge_point(side.opposite, x, 0)
            door = e.Door(Lockable(locked=rect is locked_room))
            self.map_canvas.set_architecture(point, door)

        self.hallway_area = Blob.from_rectangle(hallway)
        self.locked_area = Blob.from_rectangle(locked_room)
        self.rooms_area = reduce(operator.add, (Blob.from_rectangle(rect) for rect in rooms if rect is not locked_room))
github eevee / flax / flax / fractor.py View on Github external
from flax.component import Lockable

        # Add some doors for funsies.
        locked_room = random.choice(rooms)
        for rect in rooms:
            x = random.randrange(rect.left + 1, rect.right - 1)
            if rect.top > hallway.top:
                side = Direction.down
            else:
                side = Direction.up
            point = rect.edge_point(side.opposite, x, 0)
            door = e.Door(Lockable(locked=rect is locked_room))
            self.map_canvas.set_architecture(point, door)

        self.hallway_area = Blob.from_rectangle(hallway)
        self.locked_area = Blob.from_rectangle(locked_room)
        self.rooms_area = reduce(operator.add, (Blob.from_rectangle(rect) for rect in rooms if rect is not locked_room))
github eevee / flax / flax / fractor.py View on Github external
from flax.component import Lockable

        # Add some doors for funsies.
        locked_room = random.choice(rooms)
        for rect in rooms:
            x = random.randrange(rect.left + 1, rect.right - 1)
            if rect.top > hallway.top:
                side = Direction.down
            else:
                side = Direction.up
            point = rect.edge_point(side.opposite, x, 0)
            door = e.Door(Lockable(locked=rect is locked_room))
            self.map_canvas.set_architecture(point, door)

        self.hallway_area = Blob.from_rectangle(hallway)
        self.locked_area = Blob.from_rectangle(locked_room)
        self.rooms_area = reduce(operator.add, (Blob.from_rectangle(rect) for rect in rooms if rect is not locked_room))