示例#1
0
文件: pillar.py 项目: aagontuk/ekush
class Pillar(object):
    """
    Pillar object.

    A pillar is a complex shape composed
    of three rectangle. 2 columns and a beam. Example:

        2
     ________
     |______|
   1 | |  | | 3
     | |  | |
     | |  | |

    Args:
        x (int): x coordinate of the bottom left corner
                of the first pillar

        y (int): y coordinate of the bottom left corner
                of the first pillar

        height (int): height of the pillar

        width (int): width of the pillar

        thickness (int): Thickness of the pillar columns and beams
    """
    def __init__(self, x, y, height, width, thickness):
        self.x = x
        self.y = y
        self.height = height
        self.width = width
        self.thickness = thickness
        self.col1 = None
        self.beam2 = None
        self.col2 = None

    def draw(self):
        """ Draw pillar """
        self.col1 = Rectangle(self.x, self.y, self.height, self.thickness)
        self.col1.draw()

        x, y = self.col1.top_left
        self.beam1 = Rectangle(x, y, self.thickness, self.width)
        self.beam1.draw()

        x, y = self.col1.bottom_left
        x = x + self.width - self.thickness
        self.col2 = Rectangle(x, y, self.height, self.thickness)
        self.col2.draw()

    def far_left(self):
        """ Returns bottom left coordinate of the left column """
        return self.x, self.y

    def far_right(self):
        """ Returns bottom right coordinate of the right column """
        return self.col2.bottom_right

    def prettify(self):
        """
        Erase common section between left column and beam.
        And between right column and beam.
        """
        x1, y1 = self.beam1.bottom_left
        x2, y2 = x1 + self.thickness, y1
        self.beam1.erase((x1 + 1, y1), (x2 - 1, y2))

        x1, y1 = self.beam1.bottom_right
        x2, y2 = x1 - self.thickness, y1
        self.beam1.erase((x2 + 1, y2), (x1 - 1, y1))
示例#2
0
def mainPillar(x, y, bottom_height, top_height, width, thickness):
    # Draw bottom column 1
    col1 = Rectangle(x, y, bottom_height, thickness)
    col1.draw()

    # Draw bottom column 2
    x, y = col1.bottom_right
    col2 = Rectangle(x + width, y, bottom_height, thickness)
    col2.draw()

    # Draw rods inside col1 and col2
    roddist = width / 3
    x, y = col1.bottom_right
    draw_rods(x, y, bottom_height, roddist)

    # Draw bottom column 3
    x, y = col2.bottom_right
    col3 = Rectangle(x + width, y, bottom_height, thickness)
    col3.draw()

    # Draw rods inside col2 and col3
    x, y = col2.bottom_right
    draw_rods(x, y, bottom_height, roddist)

    x1, y1 = col1.top_left
    x2, y2 = col3.top_left

    turtle.penup()
    turtle.setpos(x1, y1)
    turtle.setheading(0)
    turtle.pendown()
    turtle.forward(turtle.distance(x2, y2))

    # Draw top column 1
    x, y = col1.top_left
    col4 = Rectangle(x, y, top_height, thickness)
    col4.draw_right(30)

    # Draw top column 2
    x, y = col2.top_left
    col5 = Rectangle(x, y, top_height, thickness)
    col5.draw_right(30)

    # Draw rods inside col4 and col5
    x, y = col4.bottom_right
    draw_rods(x, y, top_height, roddist, -30)

    # Draw top column 3
    x, y = col2.top_left
    x, y = col3.top_left
    col6 = Rectangle(x, y, top_height, thickness)
    col6.draw_right(30)

    # Draw rods inside col5 and col6
    x, y = col5.bottom_right
    draw_rods(x, y, top_height, roddist, -30)

    x, y = col4.top_left

    beam1 = Rectangle(x, y + 1, thickness, width * 2 + 30)
    beam1.draw_right(30)

    # Remove intersection of coloumn 4 and beam 1
    x, y = beam1.bottom_left
    print((x, y))
    beam1.erase((x + 1, y), (x + thickness - 1, y))

    # Remove intersection of coloumn 5 and beam 1
    x, y = col5.top_left
    print((x, y))
    beam1.erase((x + 1, y + 1), (x + thickness + 2, y))

    # Remove intersection of coloumn 5 and beam 1
    x, y = col6.top_left
    print((x, y))
    beam1.erase((x + 1, y + 1), (x + thickness + 2, y))

    return col3.bottom_right