Exemplo n.º 1
0
    def __init__(self, cls_Wall=Wall):
        ElementGroup.__init__(self, (0, 0, 0), Facing.FRONT)

        for y in range(0, 8 * 8 * 24, 8 * 24):
            self.append(WallBox((0, y, 0), (31 * 40, y + 24 * 8, 20 * 16), front=False, cls_wall=cls_Wall))

            self.append(
                cls_Wall((0, y, 0), (31 * 40, y + 24 * 2, 0),
                         connections=Connections(left=BRICK_EVEN, right=BRICK_EVEN)))
            self.append(WindowWall((0, y + 24 * 2, 0), 31, cls_wall=cls_Wall,
                                   connections=Connections(left=BRICK_EVEN, right=BRICK_EVEN)))
Exemplo n.º 2
0
    def __init__(self,
                 pixels,
                 pos,
                 color,
                 facing=Facing.FRONT,
                 pos_b=None,
                 connections=Connections()):
        ElementGroup.__init__(self,
                              pos,
                              facing,
                              pos_b=pos_b,
                              connections=connections)

        self.color = color
        self.pixels = pixels
        self.occupied = [[False] * len(row) for row in self.pixels]
        # image top left to bottom right

        self.positions = []
        for index_row, row in enumerate(self.pixels):
            for index_column, pixel in enumerate(row):
                if pixel != 0:
                    self.positions.append((index_column, 0, index_row))

        while len(self.positions) > 0:
            position = random.choice(self.positions)
            print(position, len(self.positions))
            random.shuffle(parts)

            for part in parts:
                if self.fits(position, part):
                    self.put(position, part)
                    break
Exemplo n.º 3
0
    def __init__(self,
                 im,
                 pos,
                 facing=Facing.FRONT,
                 pos_b=None,
                 connections=Connections()):
        ElementGroup.__init__(self, pos, facing, pos_b, connections)
        pixels = list(im.getdata())
        width, height = im.size
        present_colors = list(c for c in set(pixels) if c[3] == 255)

        reverse_colors = {
            ImageColor.getrgb(c.rgb) + (255, ): c
            for c in OpaqueColors
        }

        for c in present_colors:
            if c[3] != 255:
                continue
            colored_pixels = [1 if x == c and x[3] > 0 else 0 for x in pixels]
            colored_pixels = [
                colored_pixels[i * width:(i + 1) * width]
                for i in xrange(height)
            ]
            self.append(
                FillArea(colored_pixels, pos, reverse_colors[c], facing,
                         pos_b))
Exemplo n.º 4
0
    def __init__(self,
                 image_path,
                 pos,
                 facing=Facing.FRONT,
                 pos_b=None,
                 connections=Connections()):
        ElementGroup.__init__(self,
                              pos,
                              facing,
                              pos_b,
                              connections=connections)

        size = 32, 32

        im = Image.open('logo.png')
        im.thumbnail(size)

        back = get_alpha(im)
        palette = [el for c in OpaqueColors for el in ImageColor.getrgb(c.rgb)]

        paletted = get_paletted(im, palette)
        back.save('~logoback.png')
        paletted.save('~logopaletted.png')

        self.append(PillowImageElement(back, pos, Colors.Black, facing, pos_b))
        self.append(
            ColoredPillowImageElement(paletted,
                                      (pos[0], pos[1] + lduy(1), pos[2]),
                                      facing, pos_b))
Exemplo n.º 5
0
    def __init__(self, a, b, cls_wall=Wall, front=True, facing=Facing.FRONT, connections=Connections()):
        ElementGroup.__init__(self, a, facing, pos_b=b, connections=connections)

        if front:
            self.append(cls_wall(a, (b[0], b[1], a[2]),
                                 facing=Facing.FRONT,
                                 connections=Connections(left=BRICK_EVEN, right=BRICK_EVEN)))
        self.append(cls_wall(a, (a[0], b[1], b[2]),
                             facing=Facing.LEFT,
                             connections=Connections(left=BRICK_ODD, right=BRICK_ODD)))
        self.append(cls_wall((a[0], a[1], b[2] - 20), (b[0], b[1], b[2] - 20),
                             facing=Facing.BACK,
                             connections=Connections(left=BRICK_EVEN, right=BRICK_EVEN)))
        self.append(cls_wall((b[0] - 20, a[1], a[2]), (b[0] - 20, b[1], b[2]),
                             facing=Facing.RIGHT,
                             connections=Connections(left=BRICK_ODD, right=BRICK_ODD)))
Exemplo n.º 6
0
    def __init__(self, pos, pos_b, facing=Facing.FRONT, connections=Connections()):
        ElementGroup.__init__(self, pos, facing, pos_b=pos_b, connections=connections)

        pos = self.relative_pos(pos)
        pos_b = self.relative_pos(pos_b)

        for x in range(pos[0], pos_b[0], 20 * 2):
            for y in range(pos[1], pos_b[1], 24):
                offset = 20
                part = Brick1X2

                if connections.left and (y / 24) % 2 == int(connections.left != BRICK_EVEN):
                    offset = 40
                    if x == pos_b[0] - 40:
                        if connections.right:
                            continue
                        else:
                            offset = 30
                            part = Brick1X1

                last_one = (abs(pos_b[0] - pos[0]) == 40)

                if last_one and connections.right and (y / 24) % 2 == int(connections.right != BRICK_EVEN):
                    offset = 10
                    part = Brick1X1

                self.append(Element((x + offset, y, 10 + pos[2]), facing, part=part, color=Colors.Sand_Blue))
Exemplo n.º 7
0
    def __init__(self, start, width, facing=Facing.FRONT, connections=Connections(), cls_wall=Wall):
        ElementGroup.__init__(self, start, facing, connections=connections)

        self.append(cls_wall((start[0], start[1], start[2]), (start[0] + 40, start[1] + 6 * 24, start[2]),
                         connections=Connections(left=connections.left)))

        last_solid = True
        x = 40
        while x < start[facing.x] + width * 40 - 40:
            if last_solid:
                last_solid = False
                if random() > .5:
                    # Door
                    self.append(Element((start[0] + x + 40, start[1], start[2] + 10), facing, part=Door1X4X6Frame,
                                        color=Colors.Tan))
                    if random() > .5:
                        self.append(
                            Element((start[0] + x + 20 - 12, start[1], start[2] + 10), facing, part=Door1X4X6With4Panes,
                                    color=Colors.Black))
                    else:
                        self.append(Element((start[0] + x + 40, start[1] + 4, start[2] + 10), facing, part=Glass1X4X6,
                                            color=Colors.Trans_Clear))
                else:
                    self.append(cls_wall((start[0] + x, start[1] + 4 * 24, start[2]),
                                     (start[0] + x + 80, start[1] + 6 * 24, start[2])))
                    for wx in [start[0] + x + 20, start[0] + x + 60]:
                        for wy in [start[1], start[1] + 48]:
                            self.append(Element((wx, wy, start[2] + 10), facing, part=Window1X2X2, color=Colors.Tan))
                x += 80
            else:
                last_solid = True
                self.append(Wall((start[0] + x, start[1], start[2]), (start[0] + x + 40, start[1] + 6 * 24, start[2])))
                x += 40

        self.append(cls_wall((start[0] + x, start[1], start[2]), (start[0] + x + 40, start[1] + 6 * 24, start[2]),
                         connections=Connections(right=connections.right)))
Exemplo n.º 8
0
 def __init__(self,
              im,
              pos,
              color=Colors.Black,
              facing=Facing.FRONT,
              pos_b=None,
              connections=Connections()):
     pixels = list(im.getdata())
     width, height = im.size
     pixels = [pixels[i * width:(i + 1) * width] for i in xrange(height)]
     FillArea.__init__(self,
                       pixels,
                       pos,
                       color,
                       facing,
                       pos_b,
                       connections=connections)
Exemplo n.º 9
0
    def __init__(self,
                 pos,
                 pos_b,
                 facing=Facing.FRONT,
                 connections=Connections()):
        ElementGroup.__init__(self,
                              pos,
                              facing,
                              pos_b=pos_b,
                              connections=connections)

        x = 0
        y = 0
        z = 0

        nfails = 0
        self.current_height = [0] * (n_x)
        self.top_part = {}

        while True:
            if all(h == n_y for h in self.current_height):
                break

            def try_place(x, part):
                print(x)
                y = self.current_height[x]
                current_top_part = self.top_part.get(x)
                print((x, y))
                print('trying placing %s' % (ldrawparts.parts_by_code[part], ))

                width = widths[part]
                height = heights[part]

                if self.current_height[x] == n_y:
                    if x >= n_x:
                        return 0
                    else:
                        return x + 1
                for xi in range(x, min(n_x, x + width), 1):
                    if self.current_height[xi] < y:
                        print('overhang')
                        return None

                if x == 0:
                    color = Colors.Red
                else:
                    color = random.choice(WallColors)

                x_element = x
                y_element = y
                z_offset = -z_offsets[part]
                pos_element = (x_element + width / 2.0, y_element + height,
                               z_offset)

                element = Element(ldu(pos_element),
                                  facing,
                                  part=part,
                                  color=color)

                if x + width <= n_x:
                    if x + width == n_x:
                        print('end of the line')
                        element.color = Colors.Purple
                        x = 0
                    else:
                        x = x + width

                    fits = True
                    for xi in range(x_element, x_element + width, 1):
                        if xi >= n_x:
                            fits = False
                        if self.current_height[xi] > y_element:
                            fits = False
                        if self.current_height[xi] + height > n_y:
                            fits = False

                    if fits:
                        if current_top_part is not None:
                            accepted = accepts.get(current_top_part)
                            if accepted is not None and part not in accepted:
                                print('not accepted')
                                return

                        print('placing %s (%i %i)' %
                              (ldrawparts.parts_by_code[part], x_element,
                               y_element))
                        for xi in range(x_element, x_element + width, 1):
                            try:
                                self.current_height[xi] = y + height
                            except IndexError:
                                pass
                            self.top_part[xi] = part
                        self.append(element)
                        return x
                    else:
                        print('doesnt fit')
                        return
                else:
                    print('too wide')
                    return

            result = try_place(x, random.choice(parts))
            if result is None:
                nfails += 1
            else:
                x = result
            if nfails > 5:
                all_fail = True
                for part in parts:
                    result = try_place(x, part)
                    if result is not None:
                        all_fail = False
                        x = result
                        break
                if all_fail:

                    for part in parts:
                        result = try_place(x, part)

                    print('Aborting after failing to place anything')
                    break